Update Datatable not working

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I have a C# app where I create an empty datatable using the fillschema
method off of the SQLDataAdapter. I populate the datatable from a
parsed Excel spreadsheet and then need to update it. I have a small
routine where I hand in the datatable and the connection string:

string cmd = select * from RecordType1";
SqlDataAdapter sda = new SqlDataAdapter(cmd, conn);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
sda.InsertCommand = scb.GetInsertCommand();
sda.Update(dt);
sda.Dispose();

There is a single row in the datatable - and I get no errors, but the
database does not update. I am sure I am missing something simple
here - but I cannot figure out what it is.

Thanks,

Matt
 
Problem solved. I was calling the AcceptChanges() method on the
datatable - which was changing the RowState property of the rows to
Unchanged - so they were not being seen by the update. I
misunderstood the purpose of the AcceptChanges() call and mistakenly
thought it was to commit the rows to the datatable.

Thanks,

Matt
 
Back
Top