コード例 #1
0
        public bool them(NV_ThoiKy_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_ThoiKy_add", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pTenThoiKy = new SqlParameter("@TenThoiKy", SqlDbType.NVarChar, 200);
                    pTenThoiKy.Value = model.TenThoiKy;
                    myCommand.Parameters.Add(pTenThoiKy);

                    SqlParameter pEngName = new SqlParameter("@EngName", SqlDbType.NVarChar, 200);
                    pEngName.Value = model.EngName;
                    myCommand.Parameters.Add(pEngName);

                    SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NText);
                    pMoTa.Value = model.MoTa;
                    myCommand.Parameters.Add(pMoTa);

                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }
コード例 #2
0
        public NV_ThoiKy_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_ThoiKy_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@ID", SqlDbType.Int);
                    pID.Value = id;
                    myCommand.Parameters.Add(pID);

                    DataTable         dt;
                    NV_ThoiKy_ChiTiet model = new NV_ThoiKy_ChiTiet();

                    myConnection.Open();
                    using (SqlDataAdapter mData = new SqlDataAdapter(myCommand))
                    {
                        dt = new DataTable();
                        mData.Fill(dt);
                    }
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        model = new NV_ThoiKy_ChiTiet(dt.Rows[0]);
                    }
                    return(model);
                }
            }
        }