-
VB.net and MySQL
I am writting a database based inventory system and the company I work for is insistant upon MySQL. I have connection capabillities and can read and delete all day. The SQL insert statements are giving me nightmares. I need to send a string from a txtbox to the database. here is my insert statement. If anyone can please take a look at the syntax and let me know what I have done wrong.
Code:
Me.OdbcCommand1.Connection.Open()
Pleas dont delete me is the test table I have been using, and ESN is the field to insert the new data into.
Code:
Me.OdbcCommand1.CommandText = "INSERT INTO please_dont_delete_me (ESN) VALUES (txtesn.text)"
thanks
-
You are putting VB Code into your SQL String. The simplest way to fix it would be...
INSERT INTO please_dont_delete_me (ESN) VALUES ('" & txtesn.text & "')"
but you should probably look into parameters as a single quote can screw you all up.
-
That seemed to help the sql statement, but what about reading from the updated database table
-
-
I have changed the insert command over to what you suggested, but after that code I have an update command and disconnect command and then a combobox linked to the datasource. It hasnt added the new data I sent with the insert statement. I am not sure what I need to do to get this working. I have worked with SQL server before but I always used the prewritten statements. But they have not given that option to me on this and I am have going nuts trying to learn MySQL.
-
Are you doing a OdbcCommand1.ExecuteNonQuery() after you set the command text? Make sure the connection is opened first.
-
How about posting more code, so that we can see what exactly you're doing.
-
I got it working finally. I had the executenonquery in the wrong place. But I am sure there will be more problems arise so I will probably be back.
-
Ran accross another problem when implementing the final database instead of my mock up. here is the code that is causing the problem.
Code:
Me.OdbcCommand1.Connection.Open()
Code:
Me.OdbcCommand1.CommandText = "INSERT INTO ESN (ESN, Hex, Dec, Tech_ID, QC_ID, DEFECT_CODE, T_Stamp, Comment, Warranty_Code, Warranty_Flag) VALUES ('" & txtESN.Text & "','" & txthex.Text & "', '" & txtdec.Text & "', '" & ComboBox4.Text & "', '" & username & "', '" & strpasscomments & "','" & Me.DateTimePicker2.Text & "','" & Me.rtfQAComments.Text & "' )"
Code:
Me.OdbcCommand1.ExecuteNonQuery()
Code:
Me.OdbcCommand1.Connection.Close()
I dont have a clue as to why its freaking out when the command prompt.
-
Hmm... can you describe the actual problem that occurs with a little more detail than "freaking out?"
And how is the command prompt involved in this case?
-
the problem was with the data base actually. One field was named DEC and it was a protected word in MySQL. When I changed it , it fixed the problems I was having.