
November 8th, 2012, 11:43 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 10 m 34 sec
Reputation 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
|