sornram9254

ASP.NET (C#) - MS Access => btnSave

Apr 14th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1.         protected void btnSave_Click(object sender, EventArgs e)
  2.         {
  3.             string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\bookDB.mdb";
  4.             OleDbConnection con = new OleDbConnection(conStr);
  5.             try
  6.             {
  7.                 OleDbCommand cmd = new OleDbCommand();
  8.                 cmd.CommandText = "INSERT INTO exam_book" +
  9.                 "(name_book, author_book, pubisher_book, type_book, isbn_book, price_book, status_book, id_branch, comment_branch)" +
  10.                 "VALUES (@name_book, @author_book, @pubisher_book, @type_book, @isbn_book, @price_book, @status_book, @id_branch, @comment_branch)";
  11.                 cmd.Parameters.AddWithValue("@name_book", txt_name_book.Text);
  12.                 cmd.Parameters.AddWithValue("@author_book", txt_author_book.Text);
  13.                 cmd.Parameters.AddWithValue("@pubisher_book", txt_pubisher_book.Text);
  14.                 cmd.Parameters.AddWithValue("@type_book", txt_type_book.Text);
  15.                 cmd.Parameters.AddWithValue("@isbn_book", txt_isbn_book.Text);
  16.                 cmd.Parameters.AddWithValue("@price_book", txt_price_book.Text);
  17.                 cmd.Parameters.AddWithValue("@status_book", txt_status_book.Text);
  18.                 cmd.Parameters.AddWithValue("@id_branch", txt_id_branch.Text);
  19.                 cmd.Parameters.AddWithValue("@comment_branch", txt_comment_branch.Text);
  20.                 cmd.Connection = con;
  21.                 con.Open();
  22.                 cmd.ExecuteNonQuery();
  23.                 con.Close();
  24.             }
  25.             catch (Exception ex)
  26.             {
  27.                     Response.Write("Error");
  28.             }
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment