I want to use a dataadapter with a datatable to insert thousands of record into a 30-column sql table.
SqlDataAdapter adapter = new SqlDataAdapter();
DataTable table = new DataTable();
adapter.InsertCommand = new SqlCommand("INSERT INTO ...");
adapter.UpdateBatchSize = 1000;
DataRow r = null;
foreach(var entry in list)
{
r = table.NewRow();
r["lastchange"] = entry.TryGet("LastChangeTime");
// <- throws System.ArgumentException: Column does not belong to table
...
}
Is there any way to not manually define the schema of the datatable, but to read it from the table the insertions should take place in?