Textbox in update command is not updating

learner99

New member
Joined
Jan 22, 2011
Messages
1
Programming Experience
Beginner
I am trying to update the mysql databse using update command ,but not able to read the values .

Dim SQLCommand As String
Dim conn As New MySqlConnection
Dim mycommand As New MySqlCommand
Dim connString As String
SQLCommand = "Update detailsofpage SET Title='" + tb2.Text + "',Explanation='" + tb3.Text + "',Searchable='" + tb4.Text + "',Questions='" + tb6.Text + "' where Form_ID='" + tb1.Text + "'"
connString = "server=localhost; user id=15secs; password=password; database=sample; pooling=false;"
'Try
conn.ConnectionString = connString
conn.Open()
'Try
mycommand.Connection = conn
mycommand.CommandText = SQLCommand
mycommand.ExecuteNonQuery()
conn.Close()

thanks
 
Don't use string concatenation to insert variables into SQL code. Always use parameters and you'll save yourself all manner of grief. Follow the Blog link in my signature and check out my post on ADO.NET Parameters to see how. If you make the appropriate changes and you still have issues, post back with your new code and let us know EXACTLY what happens.
 
VB.NET:
Dim SQLCommand As String
        Dim conn As New MySqlConnection
        Dim mycommand As New MySqlCommand
        Dim connString As String
        'SQLCommand = "Update detailsofpage SET Title='" + tb2.Text + "',Explanation='" + tb3.Text + "',Searchable='" + tb4.Text + "',Questions='" + tb6.Text + "' where Form_ID='" + 

        SQLCommand = "Update detailsofpage SET Title='" & tb2.Text & "',Explanation='" & tb3.Text & "',Searchable='" & tb4.Text _
            & "',Questions='" & tb6.Text & "' where Form_ID='" &
        tb1.Text & "'"
        connString = "server=localhost; user id=15secs; password=password; database=sample; pooling=false;"
        'Try
        conn.ConnectionString = connString
        conn.Open()
        'Try
        mycommand.Connection = conn
        mycommand.CommandText = SQLCommand
        mycommand.ExecuteNonQuery()
        conn.Close()
 
VB.NET:
Dim SQLCommand As String
        Dim conn As New MySqlConnection
        Dim mycommand As New MySqlCommand
        Dim connString As String
        'SQLCommand = "Update detailsofpage SET Title='" + tb2.Text + "',Explanation='" + tb3.Text + "',Searchable='" + tb4.Text + "',Questions='" + tb6.Text + "' where Form_ID='" + 

        SQLCommand = "Update detailsofpage SET Title='" & tb2.Text & "',Explanation='" & tb3.Text & "',Searchable='" & tb4.Text _
            & "',Questions='" & tb6.Text & "' where Form_ID='" &
        tb1.Text & "'"
        connString = "server=localhost; user id=15secs; password=password; database=sample; pooling=false;"
        'Try
        conn.ConnectionString = connString
        conn.Open()
        'Try
        mycommand.Connection = conn
        mycommand.CommandText = SQLCommand
        mycommand.ExecuteNonQuery()
        conn.Close()

And what if one of the fields contains an apostrophe? The whole thing falls over. DO NOT use string concatenation. Use parameters. A mechanism has been provided to avoid these problems so use it. I used string concatenation myself to begin with, because I didn't know that parameters existed. As soon as I was enlightened though, I used them every time.
 
Back
Top