【www.gdgbn.com--Mssql】


using system.data;
using system.diagnostics;
using system.data.sqlclient;
   
string connectionstring = "data source=hg-j3ejj9lsw5py;initial catalog=test;user id=sa;password=hg";
datatable datatable = sql_.select_datagrid(" select a from large where 1=0 ").tables[0];
string passportkey;
for (int i = 0; i < 100000; i++)
{
passportkey = guid.newguid().tostring();
datarow datarow = datatable.newrow();
datarow[0] = passportkey;
datatable.rows.add(datarow);
}
sqlconnection sqlconnection = new sqlconnection(connectionstring);
sqlconnection.open();
sqltransaction sqltran = sqlconnection.begintransaction();
sqlbulkcopy sqlbulkcopy = new sqlbulkcopy(sqlconnection, sqlbulkcopyoptions.keepidentity, sqltran);
sqlbulkcopy.destinationtablename = "large";
sqlbulkcopy.batchsize = datatable.rows.count;
if (datatable != null && datatable.rows.count != 0)
{
sqlbulkcopy.writetoserver(datatable);
}
sqlbulkcopy.close();
sqltran.rollback();
sqlconnection.close();

本文来源:http://www.gdgbn.com/shujuku/29228/