Access cannot directly execute multiple statements like SQL server, but it can still be executed together to bind multiple statements into transactions.
The so-called transaction is to treat multiple things as one thing. That is, everyone is on the same ship!
One transaction is used to synchronize multiple tables, either successfully or not. The following example uses C # To handle Access database transactions:
Submit data to one table and update the data in the other table.
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Data. OleDb;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void button#click (object sender, EventArgs e)
{
String id = "";
String strCon = System. Configuration. ConfigurationManager. etettings ["ConnectStr"]. ToString ();
OleDbConnection con = new OleDbConnection (strCon );
OleDbDataAdapter adp = new OleDbDataAdapter ();
OleDbDataAdapter adp1 = new OleDbDataAdapter ();
Try
{
Con. Open ();
OleDbTransaction tra = con. BeginTransaction (); // create a transaction and start executing the transaction
Adp = new OleDbDataAdapter ("select * from sequence number table", con );
Adp. SelectCommand. Transaction = tra;
Adp1 = new OleDbDataAdapter ("select * from ", con );
Adp1.SelectCommand. Transaction = tra;
OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder (adp );
OleDbCommandBuilder thisBuilder1 = new OleDbCommandBuilder (adp1 );
DataSet ds = new DataSet ();
Adp. Fill (ds, "aa"); // Add a dataset
Id = ds. Tables ["aa"]. Rows [0] [1]. ToString ();
Int64 s = 0;
S = Convert. ToInt64 (id) + 1;
Id = s. ToString ("0000000 #");
Ds. Tables ["aa"]. Rows [0] [1] = id;
Adp. Update (ds, "aa"); // execute the transaction for modifying a table
Adp1.Fill (ds, "bb ");
DataRow dr = ds. Tables ["bb"]. NewRow ();
Dr ["ProID"] = id;
Dr ["ProName"] = "ProName ";
Dr ["ProTime"] = "2 ";
Dr ["ProIsFinish"] = "3 ";
Dr ["ProBgColor"] = "4 ";
Dr ["ProBgPic"] = "5 ";
Dr ["ProStyle"] = "6 ";
Dr ["MissionName"] = "7 ";
Dr ["ProDescription"] = "8 ";
Ds. Tables ["bb"]. Rows. Add (dr );
Adp1.Update (ds, "bb ");
Tra. Commit (); // close the transaction
}
Catch (Exception ex)
{
}
Finally
{
Con. Close ();
}
}
Note: Access transactions do not support automatic locking (confirmed by experiments). Therefore, it is best to use Access for local programs. Do not use Access in B/s unless you do not need to process transactions ~~!