|
-
Jul 9th, 2004, 03:42 PM
#1
Thread Starter
New Member
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
-
Jul 9th, 2004, 03:45 PM
#2
Frenzied Member
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.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jul 9th, 2004, 03:50 PM
#3
Thread Starter
New Member
That seemed to help the sql statement, but what about reading from the updated database table
-
Jul 9th, 2004, 03:56 PM
#4
Frenzied Member
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jul 9th, 2004, 04:05 PM
#5
Thread Starter
New Member
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.
-
Jul 9th, 2004, 04:11 PM
#6
Frenzied Member
Are you doing a OdbcCommand1.ExecuteNonQuery() after you set the command text? Make sure the connection is opened first.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jul 10th, 2004, 12:53 PM
#7
How about posting more code, so that we can see what exactly you're doing.
-
Jul 12th, 2004, 09:37 AM
#8
Thread Starter
New Member
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.
-
Jul 14th, 2004, 02:32 PM
#9
Thread Starter
New Member
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.
-
Jul 14th, 2004, 11:33 PM
#10
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?
-
Jul 15th, 2004, 11:58 AM
#11
Thread Starter
New Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|