public bool Insert(PhieuBaoHongVatTu phieuBaoHongVatTu) { try { string query = "SELECT * FROM PhieuBaoHongVatTu"; SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection); table = GetData(); DataRow row = table.NewRow(); row["tenPhieuBaoHong"] = phieuBaoHongVatTu.TenPhieuBaoHong; row["tenNguoiLap"] = phieuBaoHongVatTu.TenNguoiLap; row["ngayBao"] = phieuBaoHongVatTu.NgayBao; row["ghiChu"] = phieuBaoHongVatTu.GhiChu1; row["PhongId"] = phieuBaoHongVatTu.PhongId; row["NhanVienId"] = phieuBaoHongVatTu.NhanVienId; row["NguoiDungId"] = phieuBaoHongVatTu.NguoiDungId; table.Rows.Add(row); SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(table); return(true); } catch { return(false); } }
public bool Update(PhieuBaoHongVatTu phieuBaoHongVatTu) { try { string query = "SELECT * FROM PhieuBaoHongVatTu"; SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection); table = GetData(); table.PrimaryKey = new DataColumn[] { table.Columns[0] }; DataRow row = table.Rows.Find(phieuBaoHongVatTu.PhieuBaoHongVatTuId); if (row != null) { row["tenPhieuBaoHong"] = phieuBaoHongVatTu.TenPhieuBaoHong; row["tenNguoiLap"] = phieuBaoHongVatTu.TenNguoiLap; row["ngayBao"] = phieuBaoHongVatTu.NgayBao; row["ghiChu"] = phieuBaoHongVatTu.GhiChu1; row["PhongId"] = phieuBaoHongVatTu.PhongId; row["NhanVienId"] = phieuBaoHongVatTu.NhanVienId; row["NguoiDungId"] = phieuBaoHongVatTu.NguoiDungId; } SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(table); return(true); } catch { return(false); } }