ADO.NET 2.0 大批量数据操作和多个动态的结果集

大批量数据操作
可以利用SqlBulkCopy类快速写入大批量数据,针对SQL Server的优化,可以写入DataRow数据,DataTable,DataReader
WriteToServer(DataTable)写入数据表
WriteToServer(DataRow[])批次写入数据行
WriteToServer(DataTable ,DataRowState)按行状态写入数据库表
WriteToServer(IDataReader)写入DataReader对象
  string connstr = "server=(local);database=northwind;integrated security=true;async=true";
            
// Fill up a DataSet
            DataSet ds = new DataSet();
            SqlConnection conn 
= new SqlConnection(connstr);
            SqlDataAdapter dadp 
= new SqlDataAdapter("select * from customers", conn);
            dadp.Fill(ds);
            
// Copy the Data to SqlServer
            SqlBulkCopy bcp = new SqlBulkCopy(connstr);
            bcp.DestinationTableName 
= "customers1";
            bcp.WriteToServer(ds.Tables[
0]);

posted on 2007-01-29 15:39  玄新  阅读(192)  评论(0编辑  收藏  举报

导航