SqlDataAdapter подход
с использованием (SqlCommand insertCommand = new SqlCommand (
"INSERT BulkLoadTable (FieldA, FieldB) VALUES (@FieldA, @FieldB)", соединение))
{
insertCommand.Parameters.Add ("@ FieldA", SqlDbType.VarChar, 10, "FieldA");
insertCommand.Parameters.Add("@FieldB", SqlDbType.Int, 4, "FieldB");
// Setting UpdatedRowSource is important if you want to batch up the inserts
insertCommand.UpdatedRowSource = UpdateRowSource.None;
using (SqlDataAdapter insertAdapter = new SqlDataAdapter())
{
insertAdapter.InsertCommand = insertCommand;
// How many records to send to the database in one go (all of them)
insertAdapter.UpdateBatchSize = myDataTable.Rows.Count;
// Send the inserts to the database
insertAdapter.Update(myDataTable);
}
}