Unable to update

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Gois

Unable to update

Post by Gois » Tue 17 May 2005 11:15

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?

Serious

Post by Serious » Wed 18 May 2005 07:57

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).

GWoodcock
Posts: 3
Joined: Thu 16 Jun 2005 17:55

Similar issue in C#

Post by GWoodcock » Thu 16 Jun 2005 18:04

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...

Oleg
Devart Team
Posts: 264
Joined: Thu 28 Oct 2004 13:56

Post by Oleg » Fri 17 Jun 2005 14:50

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.

GWoodcock
Posts: 3
Joined: Thu 16 Jun 2005 17:55

Post by GWoodcock » Fri 17 Jun 2005 16:13

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!

scotru

try currency manager end current edit

Post by scotru » Sat 02 Jul 2005 03:18

Try calling the EndCurrentEdit method of the form's currency manager (available from the BindingContext collection).

[email protected]
Posts: 38
Joined: Tue 07 Mar 2006 17:13

Same problem here

Post by [email protected] » 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.

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Thu 27 Apr 2006 09:14

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.

Post Reply