Ok.
Im trying to insert a row of data into a table in a mySQL Database.
I finally got the syntax right, but now when I try and run it i get the error:
Code:Error: Unknwon Column textID.text in field list
I am using the following code:
I did find a solution, that uses $ signs, which does run successfully, but instead of inserting the text in each of the text boxes, it actually rights txtID.text in the ID cell. Close, but not quite.Code:Try cmd = New MySqlCommand cmd.CommandText = "INSERT into STAFF (ID, Name, Address1, Address2, Address3, Post_Code, DOB, Phone1, Phone2, CRB) VALUES (txtID.text, txtName.text, txtAdd1.text, txtAdd2.text, txtAdd3.txt, txtPostCode.text, txtDOB.text, txtPhone1.text, txtPhone2.txt, CRB)" cmd.CommandType = CommandType.Text cmd.Connection = cn Catch ex As Exception MsgBox(ex.Message) End Try 'Step 4 - Connect and Insert cn = New MySqlConnection() cn.ConnectionString = "server=" & My.Settings.HostIP & ";" & "user id=" & My.Settings.User & ";" & "password=" & My.Settings.Password & ";" & "database=platpos" Try cn.Open() cmd.ExecuteNonQuery() cn.Close() MsgBox("Successfully Added") Catch ex As Exception MsgBox(ex.Message) End Try
Many thanks in advance!
For those that want, the $ solution is this:
Code:Try cmd = New MySqlCommand cmd.CommandText = "INSERT into STAFF (ID, Name, Address1, Address2, Address3, Post_Code, DOB, Phone1, Phone2, CRB) VALUES ('$txtID.text', '$txtName.text', '$txtAdd1.text', '$txtAdd2.text', '$txtAdd3.txt', '$txtPostCode.text', '$txtDOB.text', '$txtPhone1.text', '$txtPhone2.txt', '$CRB')" cmd.CommandType = CommandType.Text cmd.Connection = cn Catch ex As Exception MsgBox(ex.Message) End Try 'Step 4 - Connect and Insert cn = New MySqlConnection() cn.ConnectionString = "server=" & My.Settings.HostIP & ";" & "user id=" & My.Settings.User & ";" & "password=" & My.Settings.Password & ";" & "database=platpos" Try cn.Open() cmd.ExecuteNonQuery() cn.Close() MsgBox("Successfully Added") Catch ex As Exception MsgBox(ex.Message) End Try




Reply With Quote
