Binded text fields don't update the database

  • Thread starter Thread starter Ville Mattila
  • Start date Start date
V

Ville Mattila

Hi there,

I will post my question to this group too bacause the .data group seems
to be rather quiet.

I've been playing with VB.NET and ADO for a week now and find the
different data handling functions very easy and nice. Anyway, I'm afraid
that I haven't understood the data binding things correct.

I'm using MySQL Connector/.NET to access my database from the
application. The queries work find and I'm able to fill the dataset from
data adapter to access the data.

I've binded a few text fields to the dataset in the code (I don't want
to use the Server Explorer).
Me.txtID.DataBindings.Clear()
Me.txtID.DataBindings.Add("Text", dDataset, "table.id")

For debug purposes, I've connected also a DataGrid to the dataset:
Me.DataGrid1.DataSource = dDataset

I fetch a row from the database by SELECT * FROM table WHERE
name="Ville". No problems with getting the correct values to the
textboxes. But now I try to edit the data.

I understood that since a textbox is binded to a dataset, changes made
to the textbox content will update the dataset automatically. OK, it
seems to do that correctly. I edit a textbox, the column content changes
in a datagrid as it should. Now I try to update the database with my
changes:
dAdapter.Update(dDataset, "table")

For some reason, the changes won't reach the database at all. Anyway, no
exception is thrown either.

If I edit the same field value in a datagrid and then call the update of
the data adapter, the modified data will be updated to the databse
without any problems.

Any ideeas?

Thanks for your help!

Ville
 
Ville,

Mostly is the answer to put before the update the sentence

BindingContext(ds.Tables(0)).EndCurrentEdit()

The data is pushed down in the datasource by a rowchange, and with that
command above is that forced.

When you are searching for a good ADONET newsgroup than it the newsgroup

microsoft.public.dotnet.framework.adonet
the one you are looking for

Adonet
news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet

Web interface:
http://communities2.microsoft.com/c.../?dg=microsoft.public.dotnet.framework.adonet

I hope this helps?

Cor
 
Cor said:
Mostly is the answer to put before the update the sentence

BindingContext(ds.Tables(0)).EndCurrentEdit()

Thank you Cor! I added that row to the code and the data was correctly
updated.
When you are searching for a good ADONET newsgroup than it the newsgroup

microsoft.public.dotnet.framework.adonet
the one you are looking for

Thanks for a tip too. I will subscribe there and follow the discussion
for future questions.

Best regards,
Ville
 
Back
Top