Connecting Tech Pros Worldwide Forums | Help | Site Map

Parameters MySql and VB.Net

Daniel
Guest
 
Posts: n/a
#1: Aug 10 '08
Wondering if someone could help me with adding parameters to a mysql query with vb.net

Here's my code:

mycmd = New MySqlCommand
'mycmd.Parameters.Add("?result", MySqlType.Text)
mycmd.Parameters(0).Value = "This is a test"
mycmd.Parameters(0).Direction = ParameterDirection.Input
mycmd.CommandText = "Insert into result_holder(result_id, result) Values('45',?result)"
mycmd.Connection = mycon
'Try
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try

I the exception I get is "You have an error in your sql statement near 'result'

What am I doing wrong??

Thanks!

Daniel



--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -


SuNcO
Guest
 
Posts: n/a
#2: Aug 10 '08

re: Parameters MySql and VB.Net


What do you want to do with "?result" ?

Maybe you want to send a variable ? Then is like this :

mycmd.CommandText = "Insert into result_holder (result_id, result) Values
('45'," & result & ")"

--
Windows Live Butterfly
My little blog - http://sunco.codigoplus.com (in Spanish)

"Daniel" <dan@theman.comescribió en el mensaje de
noticias:489e428f$0$26127$9a6e19ea@news.newshostin g.com...
Quote:
Wondering if someone could help me with adding parameters to a mysql query
with vb.net
>
Here's my code:
>
mycmd = New MySqlCommand
'mycmd.Parameters.Add("?result", MySqlType.Text)
mycmd.Parameters(0).Value = "This is a test"
mycmd.Parameters(0).Direction = ParameterDirection.Input
mycmd.CommandText = "Insert into result_holder(result_id, result)
Values('45',?result)"
mycmd.Connection = mycon
'Try
mycon.Open()
mycmd.ExecuteNonQuery()
mycon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
>
I the exception I get is "You have an error in your sql statement near
'result'
>
What am I doing wrong??
>
Thanks!
>
Daniel
>
>
>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -
>
Jack Jackson
Guest
 
Posts: n/a
#3: Aug 10 '08

re: Parameters MySql and VB.Net


On 10 Aug 2008 01:21:20 GMT, Daniel <dan@theman.comwrote:
Quote:
>Wondering if someone could help me with adding parameters to a mysql query with vb.net
>
>Here's my code:
>
>mycmd = New MySqlCommand
>'mycmd.Parameters.Add("?result", MySqlType.Text)
>mycmd.Parameters(0).Value = "This is a test"
>mycmd.Parameters(0).Direction = ParameterDirection.Input
>mycmd.CommandText = "Insert into result_holder(result_id, result) Values('45',?result)"
>mycmd.Connection = mycon
>'Try
>mycon.Open()
>mycmd.ExecuteNonQuery()
mycon.Close()
>Catch ex As Exception
>MsgBox(ex.Message)
>End Try
>
>I the exception I get is "You have an error in your sql statement near 'result'
>
>What am I doing wrong??
>
>Thanks!
>
>Daniel
I have never used MySql, but this link
<http://dev.mysql.com/doc/refman/5.0/en/connector-net-using-prepared.html>
uses @ instead of ? to mark parameters.
Daniel
Guest
 
Posts: n/a
#4: Aug 12 '08

re: Parameters MySql and VB.Net


That did it!! Thanks!!


--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Closed Thread