mysql insert command

hawk

Member
Joined
Sep 6, 2008
Messages
8
Programming Experience
Beginner
Hello everyone,

I'm having great difficulty inserting information into my database.

I'm hoping to insert into the table test and field alt the information in my textbox txtalt, but I just get the @alt inserted.

Any Ideas?

thanks

VB.NET:
        Dim myConnString = ";" & _
    "Database=;" & _
    "Uid=;" & _
    "Pwd=;" & _
    "Connect Timeout=30;"


        Dim myconnection As New MySqlConnection(myConnString)
        Dim command As New MySqlCommand("INSERT INTO test (alt) VALUES ('@alt')", myconnection)

        command.Parameters.AddWithValue("@alt", txtalt)

        myconnection.Open()
        command.ExecuteNonQuery()
        myconnection.Close()
 
'@alt' is a string in query, @alt is a parameter in query, if you could understand the difference... :)
 
Hello John,

I'm very new with vbnet.

I think most of what I've acheived with my script has been fairly simple but this has stumped me. It took a day to get anything to insert into the database so I asked for help from those who know. I'm very keen to learn :)
 
i thought MySQL used parameters that looked like:

?name

INSERT INTO table VALUES (?col1, ?col2)


Note to hawk: notice that i didnt put string marks around my parameter name ' ' !! You define the parameter as being of string type, you dont need to / shouldnt try and tell mysql its a string, by putting the parameter name in a string. as an example here is some vb:

Dim myNum as Integer = 7
MessageBox.Show("myNum + 3")

What does the messagebox show? Please don't say 10
 
ok what you say makes some sense ( please be gentle I'm new to this ) :D

so to insert the textbox txtalt I should use ?txtalt?
 
ok what you say makes some sense ( please be gentle I'm new to this ) :D

so to insert the textbox txtalt I should use ?txtalt?

VB.NET:
        Dim command As New MySqlCommand("INSERT INTO test (alt) VALUES (?alt)", myconnection)

        command.Parameters.AddWithValue("?alt", txtalt.text)
 
Thank you for your help, that works perfect :)

I'll be back :D

thanks again, this is the most helpful resource out there for learners :)
 
Hello guys,

Been working on this and got some good results, again thanks for all the help provided.

Now I want to update a record where a text field equals a database entry.

ie update a field in a row

I get this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (taskref) = ('666')' at line 1

any thoughts?

Thanks Again :)

VB.NET:
        Dim myconnection As New MySqlConnection(myConnString)

        Dim command As New MySqlCommand("INSERT INTO test (end) VALUES (?end) WHERE (taskref) = (?taskref)", myconnection)

        command.Parameters.AddWithValue("?end", txtQuantity.Text)
        command.Parameters.AddWithValue("?taskref", txttaskref.Text)

        myconnection.Open()
        command.ExecuteNonQuery()
        myconnection.Close()
 

Latest posts

Back
Top