Click to See Complete Forum and Search --> : MySQL db won't update


Tinchy
August 25th, 2009, 09:13 AM
I have recently moved to using VB 2008, and am having trouble getting a MySQL database to update using an ODBC driver. My code is not returning any errors and using some console.write commands I can see that the dataset is showing a row has been added, but it is not showing up in the table when i view it with phpMyAdmin - has anyone got any suggestions for what I am doing wrong?

Thanks very much!

Dim cnOdds As OdbcConnection
cnOdds = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};SERVER=[server];USER=[username];DATABASE=oddscompare;PASSWORD=[password];Option=3")

Try

cnOdds.Open()

Dim daComp As OdbcDataAdapter

daComp = New OdbcDataAdapter("SELECT * FROM Companies", cnOdds)
daComp.AcceptChangesDuringUpdate = True

Dim CommandBuilder As New OdbcCommandBuilder(daComp), cmdInsert As New OdbcCommand, cmdSelect As New OdbcCommand("SELECT * FROM Companies", cnOdds)

cmdInsert = CommandBuilder.GetInsertCommand
daComp.UpdateCommand = cmdInsert
daComp.SelectCommand = cmdSelect

Dim dsComp As DataSet = New DataSet("Companies")

daComp.Fill(dsComp, "Companies")

Dim dRow As DataRow = dsComp.Tables("Companies").NewRow

dRow("Name") = "Test"
dRow("URL") = "http://test/"
dRow("Settings") = 1

dsComp.Tables("Companies").Rows.Add(dRow)

dsComp.AcceptChanges()

daComp.Update(dsComp, "Companies")
daComp.Fill(dsComp, "Companies")

cnOdds.Close()

Catch ex As OdbcException

MsgBox(ex.ToString)

End Try

Tinchy
August 25th, 2009, 09:16 AM
P.S. - There is another ID field which is the primary index, an autoincrementing INT field.

Tinchy
August 25th, 2009, 10:18 AM
If anyone can't see a problem in the code, could they say that too? I'm really stuggling to find the solution here, despite reading about 5 tutorials on the subject :(

dannystommen
August 26th, 2009, 02:02 AM
cmdInsert = CommandBuilder.GetInsertCommand


What exactly does this auto generated command return? Debug it and see if it is the correct SQL statment