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

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.