Update Datatable not working

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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top