Results 1 to 11 of 11

Thread: VB.net and MySQL

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11

    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

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    That seemed to help the sql statement, but what about reading from the updated database table

  4. #4
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    What about it?
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    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.

  6. #6
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    How about posting more code, so that we can see what exactly you're doing.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    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.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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?

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    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
  •  



Click Here to Expand Forum to Full Width