473,587 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Paramete rs.Add("?result ", MySqlType.Text)
mycmd.Parameter s(0).Value = "This is a test"
mycmd.Parameter s(0).Direction = ParameterDirect ion.Input
mycmd.CommandTe xt = "Insert into result_holder(r esult_id, result) Values('45',?re sult)"
mycmd.Connectio n = mycon
'Try
mycon.Open()
mycmd.ExecuteNo nQuery()
mycon.Close()
Catch ex As Exception
MsgBox(ex.Messa ge)
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 4442
What do you want to do with "?result" ?

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

mycmd.CommandTe xt = "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.com escribió en el mensaje de
noticias:48**** *************** ****@news.newsh osting.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.Paramete rs.Add("?result ", MySqlType.Text)
mycmd.Parameter s(0).Value = "This is a test"
mycmd.Parameter s(0).Direction = ParameterDirect ion.Input
mycmd.CommandTe xt = "Insert into result_holder(r esult_id, result)
Values('45',?re sult)"
mycmd.Connectio n = mycon
'Try
mycon.Open()
mycmd.ExecuteNo nQuery()
mycon.Close()
Catch ex As Exception
MsgBox(ex.Messa ge)
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.com wrote:
>Wondering if someone could help me with adding parameters to a mysql query with vb.net

Here's my code:

mycmd = New MySqlCommand
'mycmd.Paramet ers.Add("?resul t", MySqlType.Text)
mycmd.Paramete rs(0).Value = "This is a test"
mycmd.Paramete rs(0).Direction = ParameterDirect ion.Input
mycmd.CommandT ext = "Insert into result_holder(r esult_id, result) Values('45',?re sult)"
mycmd.Connecti on = mycon
'Try
mycon.Open()
mycmd.ExecuteN onQuery()
mycon.Close()
Catch ex As Exception
MsgBox(ex.Mess age)
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
1818
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 as DAO objects, and the reference to dao 3.6 is present and working. The code breaks at the last statement (below) with an 'invalid arguament'...
7
21604
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 server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or...
0
3313
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 appear when someone is trying to use it as front-end for real server database systems such as PostgreSQL or MySQL. One of these problems is regarding...
1
1336
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 Insert string Dim MySQL As String = "Insert into tblusers (USERTEXT) values (@Pnotes)" 'Set up connection to mysql database Dim myConn As...
1
8818
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 form for editing. The table fill works fine, the delete function works fine, but when I try to update a row, the application fails with the...
1
3508
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 MySQL stored procedure (using mysqli) that has both input and output parameters. I have no problems passing in the relevant params, but calling the...
0
19269
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 hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
1
15375
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, lastname, from associates where username like 'nancianne' but now fails with: "You have an error in your SQL syntax; check the manual that corresponds...
1
1711
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 get this error Error 3061: Too Few Parameters.Expected 2 my code: Dim MyDB As DAO.Database
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.