Database Update Problem

  • Thread starter Thread starter Harrison N.
  • Start date Start date
H

Harrison N.

For some reason, when I used the DataAdapter.Update(DataSet,
TableName), it didn't give any error message, BUT it didn't update the
Database...

(The Dataset change is that a new row was added with all the fields
"filled in".)

Is there any reason why this would happen? Thanks!
 
Hi Harrison:
Harrison N. said:
For some reason, when I used the DataAdapter.Update(DataSet,
TableName), it didn't give any error message, BUT it didn't update the
Database...

(The Dataset change is that a new row was added with all the fields
"filled in".)

Is there any reason why this would happen?
Yes, there are a few reasons. Andy mentioned the possibility of you calling
..AcceptChanges on your datatable/dataset before calling update which is
essentially a guarantee that your changes won't be submitted to the database
b/c the rowstate of all of the rows will be reset. When you call update,
the adapter loops through the rows of the datatable and examines the
rowstate of each row. For each instance where it's modified, added or
deleted, it will call the respective command (provided one has been
provided) and execute it. So the first thing you need to do is verify that
you have changes to your dataset. Add a Debug.Assert(Not
DataSetName.HasChanges) right before you call update. If the assertion
fails, then the problem lies in the edit somewhere - basically for one
reason or another the modifications aren't visible.

Another common problem is using a try catch around update and eating the
exception without sending a notification or response - but you explicitly
mention "no error" message so this probably isn't the case.

The other likely problem is that the update command isn't matching anything
in the db.. however this will likely cause a concurrencyexception depending
on how you have your update logic configured.

In this case, the most likely case is that HasChanges is evaluating to
false. If that's the case it's good news b/c you'll probably just need to
call EndCurrentEdit or something similar.

If you would, verify the hasChanges and we'll take it from there. This may
also be helpful http://www.knowdotnet.com/articles/efficient_pt4.html

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com



Thanks!
 
William Ryan eMVP said:
Hi Harrison:

Yes, there are a few reasons. Andy mentioned the possibility of you calling
.AcceptChanges on your datatable/dataset before calling update which is
essentially a guarantee that your changes won't be submitted to the database
b/c the rowstate of all of the rows will be reset. When you call update,
the adapter loops through the rows of the datatable and examines the
rowstate of each row. For each instance where it's modified, added or
deleted, it will call the respective command (provided one has been
provided) and execute it. So the first thing you need to do is verify that
you have changes to your dataset. Add a Debug.Assert(Not
DataSetName.HasChanges) right before you call update. If the assertion
fails, then the problem lies in the edit somewhere - basically for one
reason or another the modifications aren't visible.

Another common problem is using a try catch around update and eating the
exception without sending a notification or response - but you explicitly
mention "no error" message so this probably isn't the case.

The other likely problem is that the update command isn't matching anything
in the db.. however this will likely cause a concurrencyexception depending
on how you have your update logic configured.

In this case, the most likely case is that HasChanges is evaluating to
false. If that's the case it's good news b/c you'll probably just need to
call EndCurrentEdit or something similar.

If you would, verify the hasChanges and we'll take it from there. This may
also be helpful http://www.knowdotnet.com/articles/efficient_pt4.html

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com



Thanks!

Ok, let me ask this question - I had two rows added, one to one table,
one to another, each table having it's own data adapter. I'm guessing
since AcceptChanges is called at the end of one Update, the other
Update wouldn't have any effect. Would adding the rows to one table,
"calling" that one Update, then adding the rows for the other table
and "calling" the second Update solve the problem?
 
While I'm trying to figure this out, how could I update two tables
edited through DataBindinded controls?
 
Hi Harrison
Harrison N. said:
"William Ryan eMVP" <[email protected]> wrote in message

Ok, let me ask this question - I had two rows added, one to one table,
one to another, each table having it's own data adapter. I'm guessing
since AcceptChanges is called at the end of one Update, the other
Update wouldn't have any effect.

The DataTables are separate so if you call Update on Table 0, while both
Table 0 and Table 1 have changes, only Table 0 will be affected

Would adding the rows to one table,
"calling" that one Update, then adding the rows for the other table
and "calling" the second Update solve the problem?

If I'm understanding you correctly, then no, it shouldn't.

The key is Checking the HasChanges property to determine where the problem
is. At the heart of debugging an update problme where no exception occurs
but neither does anything else, determining rowstate is critical and since
HasChanges walks through the datatable and checks the rowstate, it's the
cleanest way to determine this.

If you are positive that an exception isn't being raised and simultaneously
eaten without any notification, then the possibile problems are pretty
limited. It's most likely either a problem with rowstate (ie HasChanges is
false so Update doesn't send any chnages back to the db), the where clause
is filtering in such a way that the change isn't being reflected correctly
or it's working and just pointing to a test database or different table. A
problem with the Update/Delete/Insert commands being set up properly is
quite possible, but that won't ever show itself if you don't have changes,
so you could have multiple problems. Whichever way you look at it,
determining HasChanges is at the crux of the solution.

Let me know and we'll take it from there.

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com
 
(I replied to your first post as well) but for this one, you'd handle it the
same way as one table ... you call UPdate on an adapter that has a
configuration pointing back to the source you want udpated. In this
instance it'd basically mean calling
DataAdapter1.Update(DataSetName.Tablep[0]);
DataAdapter2.Update(DataSetName.Tables[1]);

HTH,

Bill


www.devbuzz.com
www.knowdotnet.com
 
It's strange, but according to the results I got, this is what
HasChanges Returned:
(I checked the Database, it's where the connection "points" to; there
isn't any exception being thrown...)
Before Add Row To First Table: False
After Add Row To First Table: True
After Update To First Table: True
After Add Row To Second Table: True
After Update To Second Table: True

(I'm sure this is strange and unusual...)

Is there any reasons why that is happening...?

Thanks for your help.
 
Back
Top