ADO. NET2.0 batch data operations and multiple dynamic result sets

Source: Internet
Author: User
1. large data volume operations can use the SqlBulkCopy class to quickly write large data volumes. for SQL Server optimization, DataRow data, DataTable, and DataReaderWriteToServer (DataTable) can be written to the data table WriteToServer (DataRow []). batch write data row WriteToServer (DataTable,

1. large batch data operations can use the SqlBulkCopy class to quickly write large batch data. for SQL Server optimization, DataRow data, DataTable, DataReader WriteToServer (DataTable) can be written) write Data Table WriteToServer (DataRow []) write data rows in batches WriteToServer (DataTable,

1. Large Batch Data Operation

You can use the SqlBulkCopy class to quickly write large data Batch DataFor SQL Server optimization, DataRow can be written. Data, DataTable, DataReader

WriteToServer (DataTable) Write DataTable

WriteToServer (DataRow []) Batch write DataLine

WriteToServer (DataTable, DataRowState) write data by row DataDatabase Table

WriteToServer (IDataReader) writes a DataReader object

String Connstr = " Server = (local); database = northwind; integrated security = true; async = true " ;
// Fill up a DataSet
DataSet ds = New DataSet ();
SqlConnection conn = New SqlConnection (connstr );
SqlDataAdapter dadp = New SqlDataAdapter ( " Select * from MERs " , Conn );
Dadp. Fill (ds );
// Copy the Data to SqlServer
SqlBulkCopy bcp = New SqlBulkCopy (connstr );
Bcp. DestinationTableName = " Customers1 " ;
Bcp. WriteToServer (ds. Tables [ 0 ]);
2. Multiple DynamicOf ResultSet

Multiple Active Result Sets (MARS)

This can only be used in SQL Server 2005

Multiple DataReader can be opened simultaneously on a Command object

String Connstr = " Server = (local); database = northwind; integrated security = true; async = true " ;
SqlConnection conn = New SqlConnection (connstr );
Conn. Open ();
SqlCommand cmd1 = New SqlCommand ( " Select * from MERs " , Conn );
SqlCommand cmd2 = New SqlCommand ( " Select * from orders " , Conn );
SqlDataReader rdr1 = Secrets 1.executereader ();
// Next statement causes an error prior to SQL Server 2005
SqlDataReader rdr2 = Other 2.executereader ();
// Now you can reader from rdr1 and rdr2 at the same time.

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.