public NV_CoQuanHanhChinh_ChiTiet GetById(int id) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_DM_CoQuanHanhChinh_getByID", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@id", SqlDbType.VarChar, 10); pID.Value = id; myCommand.Parameters.Add(pID); DataTable dt; NV_CoQuanHanhChinh_ChiTiet model = new NV_CoQuanHanhChinh_ChiTiet(); myConnection.Open(); using (SqlDataAdapter mData = new SqlDataAdapter(myCommand)) { dt = new DataTable(); mData.Fill(dt); } if (dt != null && dt.Rows.Count > 0) { model.CoQuanID = id; model.TenCoQuan = dt.Rows[0]["TenCoQuan"].ToString(); try { model.CapCoQuan = int.Parse(dt.Rows[0]["CapCoQuan"].ToString()); } catch { } model.ChucNang = dt.Rows[0]["ChucNang"].ToString(); model.LichSu = dt.Rows[0]["LichSu"].ToString(); model.DiaChi = dt.Rows[0]["DiaChi"].ToString(); model.ThuocTinh = dt.Rows[0]["ThuocTinh"].ToString(); model.ThuocHuyen = dt.Rows[0]["ThuocHuyen"].ToString(); model.ThuocXa = dt.Rows[0]["ThuocXa"].ToString(); model.Mota = dt.Rows[0]["MoTa"].ToString(); model.CoQuanQuanLy = dt.Rows[0]["CoQuanQuanLy"].ToString(); } return(model); } } }
public bool update(NV_CoQuanHanhChinh_ChiTiet model) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_DM_CoQuanHanhChinh_update", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@CoQuanID", SqlDbType.Int); pID.Value = model.CoQuanID; myCommand.Parameters.Add(pID); SqlParameter pTencoquan = new SqlParameter("@TenCoQuan", SqlDbType.NVarChar, 500); pTencoquan.Value = model.TenCoQuan; myCommand.Parameters.Add(pTencoquan); SqlParameter pCapcoquan = new SqlParameter("@CapCoQuan", SqlDbType.Int); pCapcoquan.Value = model.CapCoQuan; myCommand.Parameters.Add(pCapcoquan); SqlParameter pChucnang = new SqlParameter("@ChucNang", SqlDbType.NText); pChucnang.Value = model.ChucNang; myCommand.Parameters.Add(pChucnang); SqlParameter pLichsu = new SqlParameter("@LichSu", SqlDbType.NText); pLichsu.Value = model.LichSu; myCommand.Parameters.Add(pLichsu); SqlParameter pDiachi = new SqlParameter("@DiaChi", SqlDbType.NVarChar, 500); pDiachi.Value = model.DiaChi; myCommand.Parameters.Add(pDiachi); SqlParameter pThuocTinh = new SqlParameter("@ThuocTinh", SqlDbType.VarChar, 10); pThuocTinh.Value = model.ThuocTinh; myCommand.Parameters.Add(pThuocTinh); SqlParameter pThuochuyen = new SqlParameter("@ThuocHuyen", SqlDbType.VarChar, 10); pThuochuyen.Value = model.ThuocHuyen; myCommand.Parameters.Add(pThuochuyen); SqlParameter pThuocxa = new SqlParameter("@ThuocXa", SqlDbType.VarChar, 10); pThuocxa.Value = model.ThuocXa; myCommand.Parameters.Add(pThuocxa); SqlParameter pCoQuanQuanLy = new SqlParameter("@CoQuanQuanLy", SqlDbType.Int); pCoQuanQuanLy.Value = model.CoQuanQuanLy; myCommand.Parameters.Add(pCoQuanQuanLy); 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); } } } }