I'm trying out the batch inserting/updating of SqlDataAdapter. When I set UpdateBatchSize = 1, it works, but setting it to 2 gives the exception "Specified parameter name 'Id' is not valid.".
using (var sqlDataAdapter = new SqlDataAdapter
{
UpdateBatchSize = 2
})
using (var connection = new SqlConnection("Data Source=server;Initial Catalog=DB;Integrated Security=True"))
using (var command = new SqlCommand("INSERT INTO Test (Id) VALUES (@Id)", connection)
{
UpdatedRowSource = UpdateRowSource.None
})
{
command.Parameters.Add("Id", SqlDbType.Int).SourceColumn = "Id";
sqlDataAdapter.InsertCommand = command;
var table = new DataTable("Test");
table.Columns.Add("Id");
table.Rows.Add(1);
table.Rows.Add(2);
sqlDataAdapter.Update(table);
}