Updating a Dataset with one row vs. multiple rows issue

S

Sam Carleton

Ok, I am making some progress in updating a Dataset, but I am
still having some problems. I am starting with the "Walkthrough:
Displaying Data in a Windows Form Using a Parameterized Query"
which does not update its dataset. I have discovered that calling
Update() on the adapter will update the Dataset in once case but
not in another.

The case that works is that of the walkthrough, where the Dataset
has multiple rows. My table is a basic contact list, name,
address, etc. When my Dataset is "SELECT * FROM contacts WHERE
(state = ?)" which returns multiple rows and I change one of the
rows, the call on the Adapter's Update() works just fine.

On the other hand, when I change the adapter/dataset to be "SELECT
* FROM contacts WHERE (contact_id = ?)" where only one row is
returned, data is changed, the call on the Adapter's Update()
fails to make any changes to the database.

I am assuming that there is some issue when only returning one
row, verse multiple rows. Does anyone have any thoughts on this?

Sam
 
S

Sam Carleton

Ok, I am making some progress in updating a Dataset, but I am
still having some problems. I am starting with the "Walkthrough:
Displaying Data in a Windows Form Using a Parameterized Query"
which does not update its dataset. I have discovered that calling
Update() on the adapter will update the Dataset in once case but
not in another.

The case that works is that of the walkthrough, where the Dataset
has multiple rows. My table is a basic contact list, name,
address, etc. When my Dataset is "SELECT * FROM contacts WHERE
(state = ?)" which returns multiple rows and I change one of the
rows, the call on the Adapter's Update() works just fine.

On the other hand, when I change the adapter/dataset to be "SELECT
* FROM contacts WHERE (contact_id = ?)" where only one row is
returned, data is changed, the call on the Adapter's Update()
fails to make any changes to the database.

I am assuming that there is some issue when only returning one
row, verse multiple rows. Does anyone have any thoughts on this?

I am mistaken...

I had two adapters and two Datasets, AdapterState/DatasetState and
AdapterID/DatasetId. The Textboxes would bound to the
DatasetState and filled with the AdapterState, but I used the
AdapterID to update the database! When I changed thing around to
use the AdapterState to update, the database was NOT updated.

Hopefully this will sheid some light on things, any ideas?

Sam
 
B

Bart Mermuys

Hi,

Sam Carleton said:
I am mistaken...

I had two adapters and two Datasets, AdapterState/DatasetState and
AdapterID/DatasetId. The Textboxes would bound to the
DatasetState and filled with the AdapterState, but I used the
AdapterID to update the database! When I changed thing around to
use the AdapterState to update, the database was NOT updated.

Hopefully this will sheid some light on things, any ideas?

You could try to call EndCurrentEdit() on the CurrencyManager before the
Update:

// It is important for the code below that you use the same
// DataSource and DataMember(without any field) as the
// ones you used for the binding.

BindingContext[ dataSource, dataMember ].EndCurrentEdit();

eg.
BindingContext[ ContactDataSet, "Contacts" ].EndCurrentEdit();

If only the WHERE clause of your query changes then you don't need to use a
different DataSet. I urge you to use a common DataSet eg. ContactDataSet
then bind it and fill/update it with AdapterState or AdapterID.

You could also add another DataAdapter eg. AdapterAll that gets all records
("SELECT * FROM CONTACTS") and then always use that one to Update. This way
you can always use the same adapter (AdapterAll) to update regarless whether
the data came from AdapterAll, AdapterState or AdapaterID.

hth,
Greetings
 
S

Sam Carleton

Hi,

You could try to call EndCurrentEdit() on the CurrencyManager before the
Update:

// It is important for the code below that you use the same
// DataSource and DataMember(without any field) as the
// ones you used for the binding.

BindingContext[ dataSource, dataMember ].EndCurrentEdit();

That is it!!!!!!!!!!!!!!!! Man, I have been fighting this one for
a long time, thanks for the answer, I really apprecaite it!!!!!!!

Sam
 

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