public bool them(NV_LoaiVanBan_ChiTiet model) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_LoaiVanBan_Add", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pTenLoaiVanBan = new SqlParameter("@TenLoaiVanBan", SqlDbType.NVarChar, 250); pTenLoaiVanBan.Value = model.TenLoaiVanBan; myCommand.Parameters.Add(pTenLoaiVanBan); SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NVarChar, 1000); pMoTa.Value = model.MoTa; myCommand.Parameters.Add(pMoTa); try { myConnection.Open(); myCommand.ExecuteNonQuery(); return(true); } catch { return(false); } } } }
public NV_LoaiVanBan_ChiTiet GetById(int id) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_LoaiVanBan_GetByID", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@id", SqlDbType.Int); pID.Value = id; myCommand.Parameters.Add(pID); NV_LoaiVanBan_ChiTiet model = new NV_LoaiVanBan_ChiTiet(); DataTable dt; myConnection.Open(); using (SqlDataAdapter mData = new SqlDataAdapter(myCommand)) { dt = new DataTable(); mData.Fill(dt); } if (dt != null && dt.Rows.Count > 0) { model.LoaiVanBanID = id; model.TenLoaiVanBan = dt.Rows[0]["TenLoaivanBan"].ToString(); model.MoTa = dt.Rows[0]["MoTa"].ToString(); } return(model); } } }