可以利用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]);
// 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]);