By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,639 Members | 2,000 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,639 IT Pros & Developers. It's quick & easy.

MySQL: UPDATE not working

P: n/a
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
*-----------------------*
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Jos
HydroSan wrote:
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

--

Jos
Nov 21 '05 #2

P: n/a
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

--

Jos Branders
Nov 21 '05 #3

P: n/a
there s a .NET connector for mysql that doesn t use odbc sources in c#
binary release available too
100% dotnet is better :)
http://dev.mysql.com/downloads/connector/net/1.0.html

"Jos" <jn*************@fastmail.fm> a écrit dans le message de news:
uO**************@TK2MSFTNGP14.phx.gbl...
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

--

Jos Branders

Nov 21 '05 #4

P: n/a
Do you get an error? If so, what is it?
"HydroSan" <hy***@sankyuu-dot-com.no-spam.invalid> wrote in message
news:41**********@Usenet.com...
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
*-----------------------*

Nov 21 '05 #5

P: n/a
> 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
*-----------------------*
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.