Connecting Tech Pros Worldwide Forums | Help | Site Map

MySQL: UPDATE not working

HydroSan
Guest
 
Posts: n/a
#1: Nov 21 '05
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
*-----------------------*

Jos
Guest
 
Posts: n/a
#2: Nov 21 '05

re: MySQL: UPDATE not working


HydroSan wrote:[color=blue]
> 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. :([/color]

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


Jos
Guest
 
Posts: n/a
#3: Nov 21 '05

re: MySQL: UPDATE not working


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


LilBuh
Guest
 
Posts: n/a
#4: Nov 21 '05

re: MySQL: UPDATE not working


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" <jnospambranders@fastmail.fm> a écrit dans le message de news:
uOWrz81wEHA.3096@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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
>
>[/color]


Jeff Dillon
Guest
 
Posts: n/a
#5: Nov 21 '05

re: MySQL: UPDATE not working


Do you get an error? If so, what is it?


"HydroSan" <hydro@sankyuu-dot-com.no-spam.invalid> wrote in message
news:418ba336$1_4@Usenet.com...[color=blue]
> 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
> *-----------------------*[/color]


HydroSan
Guest
 
Posts: n/a
#6: Nov 21 '05

re: MySQL: UPDATE not working


> 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
*-----------------------*
Closed Thread