欢迎光临
我们一直在努力

ADO.NET 2.0 Dataset和Datatable 新功能新特性-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

1.新的索引引擎更快的执行效率
   下面这段代码在2003中需要157秒,在2005中只要11秒就可以完成:

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可以序列化为二进制文件

 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.更独立的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.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);

            sqldataadapter dadpt1 
= new sqldataadapter(“select * from customers“, connstr);
            datatable dt1 
= new datatable(“customer1“);
            dadpt1.fill(dt1);

            dt.merge(dt1);

            
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();

            datatable dt 
= new datatable(“customer“);
            dt.load(dr);

            
this.datagridview1.datasource = dt;
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ADO.NET 2.0 Dataset和Datatable 新功能新特性-.NET教程,Asp.Net开发
分享到: 更多 (0)