1. Create and open a OleDbConnection object
String strconn = "Provider = microsoft.jet.oledb.4.0; Data Source = Sample.mdb ";
OleDbConnection myconn = new OleDbConnection (Strcon);
MyConn.Open ();
2. Create an inserted SQL statement
String Strinsert = "INSERT into books (BookID, BookTitle, Bookauthor, Bookprice, Bookstock) VALUES (";
Strinsert + = T_bookid. Text + ", '";
Strinsert + = T_booktitle. Text + "', '";
Strinsert + = T_bookauthor. Text + "',";
Strinsert + = T_bookprice. Text + ",";
Strinsert + = T_bookstock. Text + ")";
3. Create a OleDbCommand object
OleDbCommand Inst = new OleDbCommand (Strinsert, myconn);
4. Using the OleDbCommand object to insert data
Inst. ExecuteNonQuery ();
5. Close OleDbConnection
Myconn.close ();
Note : When you use an Access database, you need to indicate the name of the field you want to insert data into when inserting data!
Insert data into Access using C # (for reference only)