Page 1 of 1

Unable to update

Posted: Tue 17 May 2005 11:15
by Gois
I want to use databindings with textboxes, that part is working but when I try to update one of the textboxes, the database doesn't change/update.

I'm using this code for update:

Code: Select all

    Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MyCon.Open()
        Me.MyDa1.Fill(Me.DsTest1.nieuws)
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Me.MyDa1.Update(Me.DsTest1.nieuws)
    End Sub
Am i using the wrong code or method?

Posted: Wed 18 May 2005 07:57
by Serious
To all appearance, type of MyCon object is MySqlConnection, MyDal is MySqlDataAdapter; DsTest1 is typed dataset.
Basing on this hypothesis this code is correct, probably you have problems with data binding (for more information about data binding see Web Forms Data Binding or Windows Forms Data Binding).

Similar issue in C#

Posted: Thu 16 Jun 2005 18:04
by GWoodcock
I have the same problem in C# with this code:

mySqlDataAdapter.Update (dataSet, "mytable");

All the bindings for my Windows Form text boxes, combo boxes, etc. are functioning correctly in terms of fills, inserts, and deletes, but updating does not work at all. I've tried using both TableDirect and Text methods in the data adapter, with identical results (the database fails to update).

As far as I can tell, the biggest difference between what I'm doing and the sample code I've looked at is that I'm not using a DataGrid control to interact with the database.

Is there sample code in either VB or C# somewhere that illustrates the proper method for using MySqlDirect.NET to update a database using a custom Windows Form layout with edit boxes (as opposed to a DataGrid)? A working example would clear things up the quickest for me...

Posted: Fri 17 Jun 2005 14:50
by Oleg
Check before calling

Code: Select all

mySqlDataAdapter.Update (dataSet, "mytable");
that data received in your DataTable from TextBoxes. Check that DataRow that you modified has DataRowState.Modified state.

Posted: Fri 17 Jun 2005 16:13
by GWoodcock
That's the smoking gun, alright - the DataRowState has a value of "Unchanged" instead of "Modified". So, it appears my data binding has some kind of problem, as you originally noted. Do you have any ideas as to what sort of binding problem would allow fill/insert/delete to work properly but wouldn't allow update to function correctly? Thanks for the assistance!

try currency manager end current edit

Posted: Sat 02 Jul 2005 03:18
by scotru
Try calling the EndCurrentEdit method of the form's currency manager (available from the BindingContext collection).

Same problem here

Posted: Wed 12 Apr 2006 20:10
Did anybody ever figure out a mechanism whereby they can force the update on simpe bound controls? I am able in the debugger to see that my data values are in fact changing at the MySQLDataTable level, but I can't for the life of me figure out how to "trick" the control into sending an Update command.

Posted: Thu 27 Apr 2006 09:14
by Alexey
Before calling Update() method you should change Position property of BindingContext class. This will cause DataRowState to be Modified.
PositionChanged event fires even if you change position to the current position. So take a look at the code below:

Code: Select all

Me.BindingContext(mySqlDataTable).Position = Me.BindingContext(mySqlDataTable).Position
mySqlDataTable.Update()
for MySqlDataTable component. And

Code: Select all

Me.BindingContext(dataSet11, "tablename").Position = Me.BindingContext(dataSet11, "tablename").Position
mySqlDataAdapter.Update(dataSet11, "tablename")
in case of MySqlDataAdapter.