Advertisement
thienlang

Connection Access Update

Apr 3rd, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. public bool Repair(Category cat)
  2.         {
  3.             string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ThuVien.accdb;";
  4.             OleDbConnection connection = new OleDbConnection(connectionString);
  5.             connection.Open();
  6.  
  7.             // 2. Chuẩn bị câu truy vấn
  8.             string sql = "update Category set TenSP= @TenSP, DungTich = @DungTich, DoCon = @DoCon, XuatXu = @XuatXu, Gia = @Gia where MaSP = @MaSP";
  9.  
  10.             OleDbCommand command = new OleDbCommand(sql, connection);
  11.             command.Parameters.Add("@TenSP", OleDbType.VarChar).Value = cat.TenSP;
  12.             command.Parameters.Add("@DungTich", OleDbType.Integer).Value = cat.DungTich;
  13.             command.Parameters.Add("@DoCon", OleDbType.Single).Value = cat.DoCon;
  14.             command.Parameters.Add("@XuatXu", OleDbType.VarChar).Value = cat.XuatXu;
  15.             command.Parameters.Add("@Gia", OleDbType.Integer).Value = cat.Gia;
  16.             command.Parameters.Add("@MaSP", OleDbType.VarChar).Value = cat.MaSP;
  17.  
  18.             bool ret = false;
  19.             try
  20.             {
  21.                
  22.                 ret = command.ExecuteNonQuery() == 1;
  23.             }
  24.             catch (Exception ex)
  25.             {
  26.                 connection.Close();
  27.                 return ex.Equals(false);
  28.                
  29.             }
  30.             connection.Close();
  31.             return ret;
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement