Simple Adapter.Update problem

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hi,

I have a typed dataset that is based on a SQL view, so I have added a stored
procedure to save the data (that the TableAdapater found and populated).

However when I execute "Adapter.Update(DataSet.Tables[0])", absolutely
nothing happens - no errors, no sql commands. Is there anything obvious I'm
doing wrong? How do I debug this?

Thanks,
Brian
 
Should you call DataSet.Tables[0].AcceptChanges() before this line. It is
necessary to accept changes first and then call update.
 
Zeeshan,

Calling AcceptChanges will result in no updates being persisted to the
database.

You almost never want to call AcceptChanges before updating.

Kerry Moorman


Zeeshan Gulzar said:
Should you call DataSet.Tables[0].AcceptChanges() before this line. It is
necessary to accept changes first and then call update.

Brian said:
Hi,

I have a typed dataset that is based on a SQL view, so I have added a stored
procedure to save the data (that the TableAdapater found and populated).

However when I execute "Adapter.Update(DataSet.Tables[0])", absolutely
nothing happens - no errors, no sql commands. Is there anything obvious I'm
doing wrong? How do I debug this?

Thanks,
Brian
 
Brian,

Have a look if it has changing by debuging a simple method is

if (DataSet.HasChanges)
{Adapter.Update(DataSet.Tables[0]);}

If you see it in the debugger then pass the Adapter Update, then you know
your first problem. To use this with a DataTable you have to do a kind of
strange method

if (DataSet.Tables[0].GetChanges != null) etc

Cor
 
Thank you all very much for your help. Your pointers helped me pin-point the
problems.

The HasChanges() was the key as this was false so no wonder the Update()
didn't do anything.

In the end there were 2 problems with 2 fields:
1. One column was a calculated value and was automatically marked "ReadOnly"
in the DataSet. Changing this allowed the new value to come through.
2. For the other column I didn't have the Databinding.SelectedValue set for
the ComboBox.

Again, thanks very much for your help, it is much appreciated.
Brian
 
Zeeshan:

Just to be clear, you would only want to call AcceptChanges if you *didn't*
want rows updated back on the database side. When an adapter has Update
called, it loops through each row examining the RowState values of each row.
If the RowState is unchanged, then it just moves on to the next row.
AcceptChanges does precisely that, setting the RowState to unchanged. So if
you had the following:

DataSetName.AccpetChanges();
DataAdapterName.Update(DataSetName);

you could guarantee that nothing would be updated on the back end.

Just to be clear, i wasn't in any way trying to nitpick or be critical,
rather, I just wanted to make sure there wasn't any confusion b/c in this
case, it could cause some confusion..

Cheers,

Bill
Zeeshan Gulzar said:
Should you call DataSet.Tables[0].AcceptChanges() before this line. It is
necessary to accept changes first and then call update.

Brian said:
Hi,

I have a typed dataset that is based on a SQL view, so I have added a
stored
procedure to save the data (that the TableAdapater found and populated).

However when I execute "Adapter.Update(DataSet.Tables[0])", absolutely
nothing happens - no errors, no sql commands. Is there anything obvious
I'm
doing wrong? How do I debug this?

Thanks,
Brian
 
Back
Top