public NV_NguonKinhPhi_ChiTiet GetById(int id) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_NguonKinhPhi_getByID", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@ID", SqlDbType.VarChar, 10); pID.Value = id; myCommand.Parameters.Add(pID); DataTable dt; NV_NguonKinhPhi_ChiTiet model = new NV_NguonKinhPhi_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_NguonKinhPhi_ChiTiet(dt.Rows[0]); } return(model); } } }
public bool update(NV_NguonKinhPhi_ChiTiet model) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_NguonKinhPhi_update", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@ID", SqlDbType.Int); pID.Value = model.ID; myCommand.Parameters.Add(pID); SqlParameter pNguoiDauTu = new SqlParameter("@NguoiDauTuID", SqlDbType.Int); pNguoiDauTu.Value = model.NguoiDauTuID; myCommand.Parameters.Add(pNguoiDauTu); SqlParameter pNguonKinhPhi = new SqlParameter("@NguonKinhPhiID", SqlDbType.Int); pNguonKinhPhi.Value = model.NguonKinhPhiID; myCommand.Parameters.Add(pNguonKinhPhi); SqlParameter pSoTien = new SqlParameter("@SoTien", SqlDbType.Decimal, 18); pSoTien.Value = model.SoTien; myCommand.Parameters.Add(pSoTien); SqlParameter pNgayDauTu = new SqlParameter("@NgayDauTu", SqlDbType.DateTime); pNgayDauTu.Value = model.NgayDauTu; myCommand.Parameters.Add(pNgayDauTu); SqlParameter pTienConLai = new SqlParameter("@TienConLai", SqlDbType.Decimal); pTienConLai.Value = model.TienConLai; myCommand.Parameters.Add(pTienConLai); SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NVarChar, 500); pMoTa.Value = model.MoTa; myCommand.Parameters.Add(pMoTa); SqlParameter pTaiLieu = new SqlParameter("@TaiLieu", SqlDbType.NVarChar, 50); pTaiLieu.Value = model.TaiLieu; myCommand.Parameters.Add(pTaiLieu); try { myConnection.Open(); myCommand.ExecuteNonQuery(); return(true); } catch { return(false); } } } }