CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    3

    Unhappy 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

  2. #2
    Join Date
    Aug 2009
    Posts
    3

    Re: MySQL db won't update

    P.S. - There is another ID field which is the primary index, an autoincrementing INT field.

  3. #3
    Join Date
    Aug 2009
    Posts
    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

  4. #4
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: MySQL db won't update

    Quote Originally Posted by Tinchy View Post

    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
  •  





Click Here to Expand Forum to Full Width

Featured