ADO.NET 2.0 Dataset和Datatable 新功能新特性

前端之家收集整理的这篇文章主要介绍了ADO.NET 2.0 Dataset和Datatable 新功能新特性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<p style="FONT-SIZE: 10pt">1.新的索引引擎更快的执行效率   下面这段代码在2003中需要157秒,在2005中只要11秒就可以完成:


<p style="FONT-SIZE: 10pt">DataSet ds = new DataSet();


<p style="FONT-SIZE: 10pt">            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"));


<p style="FONT-SIZE: 10pt">            Cursor.Current = Cursors.WaitCursor;


<p style="FONT-SIZE: 10pt">            DateTime datBegin = DateTime.Now;


<p style="FONT-SIZE: 10pt">            Random rand = new Random();            int i,intValue;            DataRow dr;


<p style="FONT-SIZE: 10pt">            for (i = 1; i <= 500000; i++)            {                try                {                    intValue = rand.Next();


<p style="FONT-SIZE: 10pt">                    dr = ds.Tables[0].NewRow();


<p style="FONT-SIZE: 10pt">                    dr["ID"] = intValue;                    dr["Value"] = intValue;


<p style="FONT-SIZE: 10pt">                    ds.Tables[0].Rows.Add(dr);                }                catch { }            }


<p style="FONT-SIZE: 10pt">            Cursor.Current = Cursors.Default;


<p style="FONT-SIZE: 10pt">            MessageBox.Show("Elapsed Time: " + (DateTime.Now - datBegin).Seconds.ToString());            MessageBox.Show("count = " + ds.Tables[0].Rows.Count.ToString());2.Dataset可以序列化为二进制文件 string connstr = "server=(local);database=northwind;integrated security=true;async=true";


<p style="FONT-SIZE: 10pt">            DataSet ds = new DataSet();            sqlDataAdapter dadpt = new sqlDataAdapter("select from [order details]",connstr);            dadpt.Fill(ds);


<p style="FONT-SIZE: 10pt">            BinaryFormatter bf = new BinaryFormatter();            FileStream fs = new FileStream(@"c:\xml1.txt",FileMode.OpenOrCreate);


<p style="FONT-SIZE: 10pt">            ds.RemotingFormat = SerializationFormat.Binary;


<p style="FONT-SIZE: 10pt">            bf.Serialize(fs,ds);     3.更独立的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);


<p style="FONT-SIZE: 10pt">            dt.WriteXml(@"c:\DataTable.xml",true);            dt.WriteXmlSchema(@"c:\DataTableSchema.xml");   DataTable Read XML StreamReader sr = new StreamReader(@"C:\DataTableSchema.xml");


<p style="FONT-SIZE: 10pt">            DataTable dt = new DataTable();            dt.ReadXmlSchema(sr);


<p style="FONT-SIZE: 10pt">            dt.ReadXml(new StreamReader(@"c:\dataTable.xml"));


<p style="FONT-SIZE: 10pt">            this.dataGridView1.DataSource = dt;    DataTable Merge string connstr = "server=(local);database=northwind;integrated security=true;async=true";            sqlDataAdapter dadpt = new sqlDataAdapter("select from customers",connstr);            DataTable dt = new DataTable("Customer");            dadpt.Fill(dt);


<p style="FONT-SIZE: 10pt">            sqlDataAdapter dadpt1 = new sqlDataAdapter("select
from customers",connstr);            DataTable dt1 = new DataTable("Customer1");            dadpt1.Fill(dt1);


<p style="FONT-SIZE: 10pt">            dt.Merge(dt1);


<p style="FONT-SIZE: 10pt">            this.dataGridView1.DataSource = 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();


<p style="FONT-SIZE: 10pt">            DataTable dt = new DataTable("Customer");            dt.Load(dr);


<p style="FONT-SIZE: 10pt">            this.dataGridView1.DataSource = dt;

原文链接:https://www.f2er.com/aspnet/74555.html

猜你在找的asp.Net相关文章