#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


    EVERY TIME I EXECUTE IT GOES STRAIGHT TO THE EXCEPTION AND DISPLAYS "ERROR".... CAN ANYONE TELL ME WHERE I WENT WRONG.... CODE BELOW


    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. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,400
    Rep Power
    1233
    It would be helpful if you posed the exception being thrown.

    Also your caps lock appears to be broken.

    -MBirchmeier
  4. #3
  5. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    You are trying to insert 9 values into 8 fields: you have omitted Country (or whatever it might be named) from the field list.

IMN logo majestic logo threadwatch logo seochat tools logo