Reference set: using System. data. oleDb; static string exePath = System. environment. currentDirectory; // path of the program // create a connection object OleDbConnection conn = new OleDbConnection ("provider = Microsoft. jet. OLEDB.4.0; data source = "+ exePath + @" \ file name. mdb "); 1. for example, table data (including "refresh" and "connect to Database") and conditional query are all related to query. OleDbDataAdapter private void is used to obtain data tables/queries () {conn. open (); // obtain the data table // string SQL = "select * from table name order by field 1"; // query string SQL = "s Elect * from table name where field 2 = "...; oleDbDataAdapter da = new OleDbDataAdapter (SQL, conn); // create an adaptation object DataTable dt = new DataTable (); // create a table object da. fill (dt); // use an adaptation object to Fill in the table object dataGridView1.DataSource = dt; // use the table object as the data source conn of the DataGridView. close ();} Where "get data table" is a method frequently called by nesting, so remove the conn at the beginning and end. open and Close, so as not to accumulate with Open in other methods and thus report an error. 2. oleDbCommand private void is used to add, delete, and modify table data. open (); // Add string SQL = "insert into Table Name (Field 1, Field 2, Field 3, field 4) values (...) "; // delete // string SQL =" delete from table name where field 1 = "...; // modify // string SQL = "update student set student ID = "...; oleDbCommand comm = new OleDbCommand (SQL, conn); comm. executeNonQuery (); conn. close ();} Where ExecuteNonQuery successfully changed the number of tuples, so comm. executeNonQuery () can also be transformed to judgment, prompting the user to succeed or fail. Int I = comm. ExecuteNonQuery (); if (I> 0) {MessageBox. Show ("data added successfully! "," Operation prompt ", MessageBoxButtons. OK, MessageBoxIcon. Information);} else {MessageBox. Show (" adding failed! "," Operation prompt ", MessageBoxButtons. OK, MessageBoxIcon. error);} 3. save private void saveData2 () {dataGridView1.EndEdit (); string SQL = "select * from table name"; OleDbDataAdapter da = new OleDbDataAdapter (SQL, conn) for data changes in the DataGridView ); oleDbCommandBuilder bld = new OleDbCommandBuilder (da); da. updateCommand = bld. getUpdateCommand (); // assign the DataGridView dview to dataTbale. (DataTable) refers to type conversion, provided that the following things can be converted to the able type dataTable dt = (DataTable) dataGridView1.DataSource; da. update (dt); dt. acceptChanges (); conn. close ();}