473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parameters MySql and VB.Net

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
------------------- ----- ---- -- -

Aug 10 '08 #1
3 4433
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" <da*@theman.comescribió en el mensaje de
noticias:48***********************@news.newshostin g.com...
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
------------------- ----- ---- -- -
Aug 10 '08 #2
On 10 Aug 2008 01:21:20 GMT, Daniel <da*@theman.comwrote:
>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.
Aug 10 '08 #3
That did it!! Thanks!!
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Aug 12 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerry Abbott | last post by:
Hi all I'm converting a db from Acc97 to 2000. Everything works, except assigning of a qdf object containing parameters, to a recordset. The db, recordset, and qrydef objects are all referenced...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
1
by: Paul | last post by:
Can someone tell me why the following code does not work ? It does not crash or cause errors and it creates a new row in the table "tblusers" but the fields are NULL. Sub doInsert() 'Create...
1
by: Mikey G | last post by:
Hi, I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL database and loads a table into a Dataset, and then displays that table information in a DataGrid on a...
1
by: evan.lavidor | last post by:
Hi all, Forgive me if this topic has been discussed before. I've been doing some searching and have yet to come across the answer I'm looking for. I'm new to PHP, and I'm trying to call a...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
1
by: totomalas | last post by:
I am trying to run the following code, where a query runs by taking some values from a form, then a recordset is intialized to count the records from the query result.... but each time i run, i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.