For the insertion and update of massive data, ADO. NET is indeed inferior to JDBC, and JDBC has a unified model for batch operations.
Very convenient:
PreparedStatement ps = conn. prepareStatement ("insert or update arg1, args2 ....");
Then you can
For (int I = 0; I <1000000000000000; I ++ ){
Ps. setXXX (realArg );
.....
Ps. addBatch ();
If (I % 500 = 0) {// assume that five hundred entries are submitted once.
Ps.exe cuteBatch ();
// Clear Parame Batch
}
}
Ps.exe cuteBatch ();
This operation not only brings about extremely high performance, but also is very convenient. To implement this function in ADO. NET, it should be directly in the Command interface.
Or the DataAdapter interface provides Addbat and CommitBat APIs, but ADO. NET does not implement this simply, but requires developers to pass
Complex workarounds.
For a large number of insert operations, you can use an empty able to Add rows to be inserted. after a certain number of rows are submitted, you can clear the table,
Implementation is not complicated:
DateTime begin = DateTime. Now;
String connectionString = ......;
Using (SqlConnection conn = new SqlConnection (connectionString ))...{
Conn. Open ();
SqlDataAdapter sd = new SqlDataAdapter ();
Sd. SelectCommand = new SqlCommand ("select devid, data_time, data_value from CurrentTest", conn );
Sd. InsertCommand = new SqlCommand ("insert into CurrentTest (devid, data_time, data_value )"
+ "Values (@ devid, @ data_time, @ data_value);", conn );
Sd. InsertCommand. Parameters. Add ("@ devid", SqlDbType. Char, 18, "devid ");
Sd. InsertCommand. Parameters. Add ("@ data_time", SqlDbType. Char, 19, "data_time ");
Sd. InsertCommand. Parameters. Add ("@ data_value", SqlDbType. Int, 8, "data_value ");
Sd. InsertCommand. UpdatedRowSource = UpdateRowSource. None;
Sd. UpdateBatchSize = 0;
DataSet dataset =