c#

位置:IT落伍者 >> c# >> 浏览文章

ADO.NET 2.0 Dataset和Datatable 新功能新


发布日期:2020年08月26日
 
ADO.NET 2.0 Dataset和Datatable 新功能新

新的索引引擎更快的执行效率

下面这段代码在中需要中只要秒就可以完成

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;

               

上一篇:.net知识结构

下一篇:C#中使用钩子控制鼠标实现代码