New Features of ADO. NET 2.0 Dataset and able

Source: Internet
Author: User
1. Faster execution efficiency of the new index Engine
The following code takes 2003 seconds in 157 and 11 seconds in 2005: DataSet ds = new DataSet ();

Ds. Tables. Add ("BigTable ");
Ds. Tables [0]. Columns. Add ("ID", Type. GetType ("System. Int32 "));
Ds. Tables [0]. Columns ["ID"]. Unique = true;
Ds. Tables [0]. Columns. Add ("Value", Type. GetType ("System. Int32 "));

Cursor. Current = Cursors. WaitCursor;

DateTime datBegin = DateTime. Now;

Random rand = new Random ();
Int I, intValue;
DataRow dr;

For (I = 1; I <= 500000; I ++)
{
Try
{
IntValue = rand. Next ();

Dr = ds. Tables [0]. NewRow ();

Dr ["ID"] = intValue;
Dr ["Value"] = intValue;

Ds. Tables [0]. Rows. Add (dr );
}
Catch {}
}

Cursor. Current = Cursors. Default;

MessageBox. Show ("Elapsed Time:" + (DateTime. Now-datBegin). Seconds. ToString ());
MessageBox. Show ("count =" + ds. Tables [0]. Rows. Count. ToString ());

2. Dataset can be serialized as a binary file string connstr = "server = (local); database = northwind; integrated security = true; async = true ";

DataSet ds = new DataSet ();
SqlDataAdapter dadpt = new SqlDataAdapter ("select * from [order details]", connstr );
Dadpt. Fill (ds );

BinaryFormatter bf = new BinaryFormatter ();
FileStream fs = new FileStream (@ "c: \ xml1.txt", FileMode. OpenOrCreate );

Ds. RemotingFormat = SerializationFormat. Binary;

Bf. Serialize (fs, ds );

3. More Independent Datatable
DataTable Write XML

String connstr = "server = (local); database = northwind; integrated security = true; async = true ";
SqlDataAdapter dadpt = new SqlDataAdapter ("select * from [order details]", connstr );
DataTable dt = new DataTable ("Customer ");
Dadpt. Fill (dt );

Dt. WriteXml (@ "c: \ DataTable. xml", true );
Dt. WriteXmlSchema (@ "c: \ DataTableSchema. xml ");

DataTable Read XML StreamReader sr = new StreamReader (@ "C: \ DataTableSchema. xml ");

DataTable dt = new DataTable ();
Dt. ReadXmlSchema (sr );

Dt. ReadXml (new StreamReader (@ "c: \ dataTable. xml "));

This. Maid = dt;

DataTable Merge string connstr = "server = (local); database = northwind; integrated security = true; async = true ";
SqlDataAdapter dadpt = new SqlDataAdapter ("select * from MERs", connstr );
DataTable dt = new DataTable ("Customer ");
Dadpt. Fill (dt );

SqlDataAdapter dadpt1 = new SqlDataAdapter ("select * from MERs", connstr );
DataTable dt1 = new DataTable ("Customer1 ");
Dadpt1.Fill (dt1 );

Dt. Merge (dt1 );

This. Maid = dt;

DataTable Load DataReader string connstr = "server = (local); database = northwind; integrated security = true; async = true ";
SqlConnection conn = new SqlConnection (connstr );
Conn. Open ();
SqlCommand cmd = new SqlCommand ("select * from [order details]", conn );
SqlDataReader dr = cmd. ExecuteReader ();

DataTable dt = new DataTable ("Customer ");
Dt. Load (dr );

This. Maid = dt;

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.