Technical solution:
A new feature of ADO. net2.0: sqlbulkcopy. For this performance, I personally tested the performance a long time ago and the efficiency was very high.
Code
/// <Summary>
/// Use sqlbulkcopy to insert data
/// </Summary>
/// <Param name = "datatable"> </param>
/// <Returns> </returns>
Private Static long sqlbulkcopyinsert ()
{
Stopwatch stopwatch = new stopwatch ();
Stopwatch. Start ();
Datatable = gettableschema ();
String passportkey;
For (INT I = 0; I <count; I ++)
{
Passportkey = guid. newguid (). tostring ();
Datarow = datatable. newrow ();
Datarow [0] = passportkey;
Datatable. Rows. Add (datarow );
}
Sqlbulkcopy = new sqlbulkcopy (connectionstring );
Sqlbulkcopy. destinationtablename = "Passport ";
Sqlbulkcopy. batchsize = datatable. Rows. count;
Sqlconnection = new sqlconnection (connectionstring );
Sqlconnection. open ();
If (datatable! = NULL & datatable. Rows. Count! = 0)
{
Sqlbulkcopy. writetoserver (datatable );
}
Sqlbulkcopy. Close ();
Sqlconnection. Close ();
Stopwatch. Stop ();
Return stopwatch. elapsedmilliseconds;
} Private Static datatable gettableschema ()
{
Datatable = new datatable ();
Datatable. Columns. addrange (New datacolumn [] {New datacolumn ("passportkey ")});
Return datatable;
}