1.新的索引引擎更快的执行效率
下面这段代码在2003中需要157秒,在2005中只要11秒就可以完成:
DataSet ds = new DataSet();
![](/Images/OutliningIndicators/None.gif)
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"));
![](/Images/OutliningIndicators/None.gif)
Cursor.Current = Cursors.WaitCursor;
![](/Images/OutliningIndicators/None.gif)
DateTime datBegin = DateTime.Now;
![](/Images/OutliningIndicators/None.gif)
Random rand = new Random();
int i, intValue;
DataRow dr;
![](/Images/OutliningIndicators/None.gif)
for (i = 1; i <= 500000; i++)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
try
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
intValue = rand.Next();
![](/Images/OutliningIndicators/InBlock.gif)
dr = ds.Tables[0].NewRow();
![](/Images/OutliningIndicators/InBlock.gif)
dr["ID"] = intValue;
dr["Value"] = intValue;
![](/Images/OutliningIndicators/InBlock.gif)
ds.Tables[0].Rows.Add(dr);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch
{ }
}
![](/Images/OutliningIndicators/None.gif)
Cursor.Current = Cursors.Default;
![](/Images/OutliningIndicators/None.gif)
MessageBox.Show("Elapsed Time: " + (DateTime.Now - datBegin).Seconds.ToString());
MessageBox.Show("count = " + ds.Tables[0].Rows.Count.ToString());
![](/Images/OutliningIndicators/None.gif)
2.Dataset可以序列化为二进制文件
string connstr = "server=(local);database=northwind;integrated security=true;async=true";
![](/Images/OutliningIndicators/None.gif)
DataSet ds = new DataSet();
SqlDataAdapter dadpt = new SqlDataAdapter("select * from [order details]", connstr);
dadpt.Fill(ds);
![](/Images/OutliningIndicators/None.gif)
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = new FileStream(@"c:\xml1.txt",FileMode.OpenOrCreate);
![](/Images/OutliningIndicators/None.gif)
ds.RemotingFormat = SerializationFormat.Binary;
![](/Images/OutliningIndicators/None.gif)
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);
![](/Images/OutliningIndicators/None.gif)
dt.WriteXml(@"c:\DataTable.xml",true);
dt.WriteXmlSchema(@"c:\DataTableSchema.xml"); DataTable Read XML
StreamReader sr = new StreamReader(@"C:\DataTableSchema.xml");
![](/Images/OutliningIndicators/None.gif)
DataTable dt = new DataTable();
dt.ReadXmlSchema(sr);
![](/Images/OutliningIndicators/None.gif)
dt.ReadXml(new StreamReader(@"c:\dataTable.xml"));
![](/Images/OutliningIndicators/None.gif)
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);
![](/Images/OutliningIndicators/None.gif)
SqlDataAdapter dadpt1 = new SqlDataAdapter("select * from customers", connstr);
DataTable dt1 = new DataTable("Customer1");
dadpt1.Fill(dt1);
![](/Images/OutliningIndicators/None.gif)
dt.Merge(dt1);
![](/Images/OutliningIndicators/None.gif)
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();
![](/Images/OutliningIndicators/None.gif)
DataTable dt = new DataTable("Customer");
dt.Load(dr);
![](/Images/OutliningIndicators/None.gif)
this.dataGridView1.DataSource = dt;