Ado. NET 2.0 large volume data operations and multiple dynamic result sets

Source: Internet
Author: User
1. Massive Data Operations
You can use the sqlbulkcopy class to quickly write large volumes of data. for SQL Server optimization, you can write datarow data, datatable, datareader
Writetoserver (datatable) write data table
Writetoserver (datarow []) Batch write data rows
Writetoserver (datatable, datarowstate) writes data to the database table by row
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 Dynamic result sets
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.