public bool Update(ThuocViPham thuocViPham) { try { string query = "SELECT * FROM ThuocViPham"; SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection); DataRow row = table.Rows.Find(thuocViPham.ThuocViPhamId); if (row != null) { row["KyLuatId "] = thuocViPham.KyLuatId; row["LoiViPhamId "] = thuocViPham.LoiViPhamId; row["lanTaiPham "] = thuocViPham.LanTaiPham; } SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(table); return(true); } catch { return(false); } }
public bool Insert(ThuocViPham thuocViPham) { try { string query = "SELECT * FROM ThuocViPham"; SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection); table = GetData(); DataRow row = table.NewRow(); row["KyLuatId "] = thuocViPham.KyLuatId; row["LoiViPhamId "] = thuocViPham.LoiViPhamId; row["lanTaiPham "] = thuocViPham.LanTaiPham; table.Rows.Add(row); SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Update(table); return(true); } catch { return(false); } }