#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Problem connecting VB 2010 to MySql database


    only the exception is being executed... where did i go wrong


    Code:
            Dim myConnString = ";" & _
            "Database = inventory;" & _
            "Uid = root;" & _
            "Pwd = root;" & _
            "Connect Timeout = 30;"
    
            Dim myconnection As New MySqlConnection(myConnString)
            Dim command As New MySqlCommand("INSERT INTO tblcustomer(CustomerID, FirstName, LastName, Address, StateProvince, ZipCode, Phone, Fax ) VALUES (@id, @fName, @lName, @addr, @state, @zip, @country, @cNumber, @fax)", myconnection)
    
    
            command.Parameters.AddWithValue("@id", id.Text)
            command.Parameters.AddWithValue("@fName", fName.Text)
            command.Parameters.AddWithValue("@lName", lName.Text)
            command.Parameters.AddWithValue("@addr", addr.Text)
            command.Parameters.AddWithValue("@state", state.Text)
            command.Parameters.AddWithValue("@zip", zip.Text)
            command.Parameters.AddWithValue("@country", country.Text)
            command.Parameters.AddWithValue("@cNumber", cNumber.Text)
            command.Parameters.AddWithValue("@fax", fax.Text)
    
    
    
            Try
                myconnection.Open()
                command.ExecuteNonQuery()
    
            Catch
                MessageBox.Show("Error")
            Finally
                myconnection.Close()
            End Try
  2. #2
  3. No Profile Picture
    Stumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,409
    Rep Power
    4538
    Did you install the mysql odbc drivers on yout machine? I'm guessing not, since your connection string doesn't specify what database server you want to use.

    There are sample connection strings on the mysql website. You'll have to look for information over there, mysql isn't a microsoft product.
    ======
    Doug G
    ======
    It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

IMN logo majestic logo threadwatch logo seochat tools logo