|
-
August 25th, 2009, 09:13 AM
#1
MySQL db won't update
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!
Code:
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
-
August 25th, 2009, 09:16 AM
#2
Re: MySQL db won't update
P.S. - There is another ID field which is the primary index, an autoincrementing INT field.
-
August 25th, 2009, 10:18 AM
#3
Re: MySQL db won't update
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
-
August 26th, 2009, 02:02 AM
#4
Re: MySQL db won't update
 Originally Posted by Tinchy
Code:
cmdInsert = CommandBuilder.GetInsertCommand
What exactly does this auto generated command return? Debug it and see if it is the correct SQL statment
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|