MySQL: UPDATE not working

H

HydroSan

Having a bit of a problem getting UPDATE working. The project in
question is a simple MySQL VB.NET frontend, allowing Insertion,
Selection, and others.

Well, I've gotten Drop and Insert working, but to edit a table row,
I'd like to use Update.

I have the following code in a class:

Private Function SQL_CustomerUpdate()
Dim MyConString As String = ("DRIVER={MySQL ODBC 3.51
Driver};SERVER=192.168.0.15;DATABASE=store;UID=hal
lo;PASSWORD=zomgnone;OPTION=3;")
Dim MyConnection As New
OdbcConnection(MyConString)
MyConnection.Open()
Dim MyCommand As New OdbcCommand
MyCommand.Connection = MyConnection
MyCommand.CommandText = "UPDATE customer SET
First_Name='ZOMG666777' WHERE id=2"
MyCommand.ExecuteNonQuery()
MyConnection.Close()
'MyConnection.Dispose()
End Function

Keep in mind that the UPDATE syntax was much more complex, but I'm
trying to get it working at a very simple level so I can see if it
actually works or not.

It doesn't. :(

Can anyone help?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
J

Jos

HydroSan said:
Having a bit of a problem getting UPDATE working. The project in
question is a simple MySQL VB.NET frontend, allowing Insertion,
Selection, and others.

Well, I've gotten Drop and Insert working, but to edit a table row,
I'd like to use Update.

I have the following code in a class:

Private Function SQL_CustomerUpdate()
Dim MyConString As String = ("DRIVER={MySQL ODBC 3.51
Driver};SERVER=192.168.0.15;DATABASE=store;UID=hal
lo;PASSWORD=zomgnone;OPTION=3;")
Dim MyConnection As New
OdbcConnection(MyConString)
MyConnection.Open()
Dim MyCommand As New OdbcCommand
MyCommand.Connection = MyConnection
MyCommand.CommandText = "UPDATE customer SET
First_Name='ZOMG666777' WHERE id=2"
MyCommand.ExecuteNonQuery()
MyConnection.Close()
'MyConnection.Dispose()
End Function

Keep in mind that the UPDATE syntax was much more complex, but I'm
trying to get it working at a very simple level so I can see if it
actually works or not.

It doesn't. :(

You didn't tell us what happens. Do you get an error message or not?

If there's no error message, check if there really is a record with ID=2.

It also helps if you wrap your code in a Try Catch exception block, like
this:

Private Function SQL_CustomerUpdate()
Dim MyConString As String = ("DRIVER={MySQL ODBC 3.51
Driver};SERVER=192.168.0.15;DATABASE=store;UID=hal
lo;PASSWORD=zomgnone;OPTION=3;")
Dim MyConnection As New OdbcConnection(MyConString)
Try
MyConnection.Open()
Dim MyCommand As New OdbcCommand
MyCommand.Connection = MyConnection
MyCommand.CommandText = "UPDATE customer SET
First_Name='ZOMG666777' WHERE id=2"
MyCommand.ExecuteNonQuery()
Catch ex As Exception
Trace.Warn(ex.ToString())
Finally
MyConnection.Close()
'MyConnection.Dispose()
End Function
 
J

Jos

Jos wrote:

Sorry, forgot the END TRY:

Private Function SQL_CustomerUpdate()
Dim MyConString As String = ("DRIVER={MySQL ODBC 3.51
Driver};SERVER=192.168.0.15;DATABASE=store;UID=hal
lo;PASSWORD=zomgnone;OPTION=3;")
Dim MyConnection As New OdbcConnection(MyConString)
Try
MyConnection.Open()
Dim MyCommand As New OdbcCommand
MyCommand.Connection = MyConnection
MyCommand.CommandText = "UPDATE customer SET
First_Name='ZOMG666777' WHERE id=2"
MyCommand.ExecuteNonQuery()
Catch ex As Exception
Trace.Warn(ex.ToString())
Finally
MyConnection.Close()
'MyConnection.Dispose()
End Try
End Function
 
H

HydroSan

Joswrote:
You didn't tell us what happens. Do you get an error message or not?

No error... and it appears that it has magically started working.

I hate when I ask a question then the problem solves itself.

Thanks for all your help. That errortrapping will come in handy one
day.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top