Writing DataGrid data back to the database.

T

Trey

I am having some real troubles with this. I have a database that is using a
oleDbAdapter to load a DataSet that shows up on a grid. I modify the text
in the grid then run the following code.

bool b = dataSet11.HasChanges();
dataSet11.AcceptChanges();
int x = dAdapt.Update(dataSet11);

Single stepping through the code I find that b is true so the dataSet has
changed. But x gets returned as a Zero saying that no rows have been
modified.

My update statement for the Adapter is:

UPDATE CallLog SET Called = ?, Company = ?, Name = ?, Notes = ?, Phone = ?,
theDate = ?, theTime = ? WHERE (theIndex = ?)

What am I doing wrong?

I appreciate your help.

Trey
 
F

Frank Oquendo

Trey said:
bool b = dataSet11.HasChanges();
dataSet11.AcceptChanges();
int x = dAdapt.Update(dataSet11);

Try something like this instead:

if (dataSet11.HasChanges())
{
dAdapt.Update(dataSet11.GetChanges());
dataSet11.AcceptChanges();
}

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 
T

Trey

Thanks, That worked!

Can you explain why? I don't understand the logic. Why do I need to only
get a dataset with the changes?
 
M

Miha Markic

Hi Trey,

You don't need to get the changes - you might.
The trick was that you call AcceptChanges *after* Update because it
consolidates the rows status in datatable (it marks them as non-changed).
 
T

Trey

Thanks!

Miha Markic said:
Hi Trey,

You don't need to get the changes - you might.
The trick was that you call AcceptChanges *after* Update because it
consolidates the rows status in datatable (it marks them as non-changed).
 

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