熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ADO.NET 2.0 Dataset和Datatable 新功能新

2013-11-13 10:16:07  來源: .NET編程 

  新的索引引擎更快的執行效率
   下面這段代碼在中需要中只要秒就可以完成

  DataSet ds = new DataSet();

  dsTablesAdd(BigTable);
            dsTables[]ColumnsAdd(ID TypeGetType(SystemInt));
            dsTables[]Columns[ID]Unique = true;
            dsTables[]ColumnsAdd(Value TypeGetType(SystemInt));

  CursorCurrent = CursorsWaitCursor;

  DateTime datBegin = DateTimeNow;

  Random rand = new Random();
            int i intValue;
            DataRow dr;

  for (i = ; i <= ; i++)
            {
                try
                {
                    intValue = randNext();

  dr = dsTables[]NewRow();

  dr[ID] = intValue;
                    dr[Value] = intValue;

  dsTables[]RowsAdd(dr);
                }
                catch { }
            }

  CursorCurrent = CursorsDefault;

  MessageBoxShow(Elapsed Time: + (DateTimeNow datBegin)SecondsToString());
            MessageBoxShow(count = + dsTables[]RowsCountToString());
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);
            dadptFill(ds);

  BinaryFormatter bf = new BinaryFormatter();
            FileStream fs = new FileStream(@c:\xmltxtFileModeOpenOrCreate);

  dsRemotingFormat = SerializationFormatBinary;

  bfSerialize(fsds);     更獨立的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);
            dadptFill(dt);

  dtWriteXml(@c:\DataTablexmltrue);
            dtWriteXmlSchema(@c:\DataTableSchemaxml);   DataTable Read XML
 StreamReader sr = new StreamReader(@C:\DataTableSchemaxml);

  DataTable dt = new DataTable();
            dtReadXmlSchema(sr);

  dtReadXml(new StreamReader(@c:\dataTablexml));

  thisdataGridViewDataSource = 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);
            dadptFill(dt);

  SqlDataAdapter dadpt = new SqlDataAdapter(select * from customers connstr);
            DataTable dt = new DataTable(Customer);
            dadptFill(dt);

  dtMerge(dt);

  thisdataGridViewDataSource = dt;  DataTable Load DataReader
 string connstr = server=(local);database=northwind;integrated security=true;async=true;
            SqlConnection conn = new SqlConnection(connstr);
            connOpen();
            SqlCommand cmd = new SqlCommand(select * from [order details] conn);
            SqlDataReader dr = cmdExecuteReader();

  DataTable dt = new DataTable(Customer);
            dtLoad(dr);

  thisdataGridViewDataSource = dt;


From:http://tw.wingwit.com/Article/program/net/201311/13114.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.