If the connection allocated to the command is in a local pending transaction, executenonquery requires the command to have a transaction. The transaction attribute of the command is still
**************************************** ****************************************
Function: Obtain and save selected data in batches to the temporary tables created by the database.
# In temp, perform necessary operations in the stored procedure according to # temp data
In this example, the transaction is used to demonstrate [incorrect title]
After you start a transaction using conn. begintransaction (), the transaction should be used for every command associated with the conn. if not used, this prompt is displayed.
**************************************** ****************************************
///DT adds the data selected on the interface to DT.
Public void shipmentsettleset (datatable DT)
{
Sqlconnection sqlc = new sqlconnection (DAL. sqlhelper. getconnectionstring ());
Sqlc. open ();
Sqltransaction sqlt = sqlc. begintransaction ();
String SQL = "select p_g_order_no into # temp from tablexx where 1 = 2 ";
Try
{
// Create a temporary table
Sqlcommand sqlcom = new sqlcommand (SQL, sqlt. Connection, sqlt );
Sqlcom. executenonquery ();
// Obtain the temporary table
Sqldataadapter SDA = new sqldataadapter ("select * from # Temp", sqlt. connection );
SDA. selectcommand. commandtype = commandtype. text;
// The following sentence must be written. Otherwise, the title will be reported.
SDA. selectcommand. Transaction = sqlt;
Datatable dttemp = new datatable ();
SDA. Fill (dttemp );//If the red part is not added, an error occurs.
For (INT I = 0; I <DT. Rows. Count; I ++)
{
Dttemp. Rows. Add (Dt. Rows [I] ["p_g_order_no"]. tostring ());
}
SQL = "insert into # temp (p_g_order_no) values (@ p_g_order_no )";
SDA. insertcommand = new sqlcommand (SQL, sqlt. Connection, sqlt );
SDA. insertcommand. commandtype = commandtype. text;
SDA. insertcommand. Parameters. Add ("@ p_g_order_no", sqldbtype. varchar, 12, "p_g_order_no ");
// Save the temporary table data
SDA. Update (dttemp );
// Operate the data of the corresponding condition of the database based on the temporary table data
Dal. shipmentsettleset (sqlt); // call the Dal layer function to perform an operation
Sqlt. Commit ();
}
Catch
{
Sqlt. rollback ();
}
Finally
{
Sqlc. Close ();
}
}
#. Net