473,387 Members | 1,582 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,387 software developers and data experts.

Do parameterized commands work with MySQL ado.net provider?

I posted it on the mySQL forum, but no one seems to be answering
questions there.

Do parameterized commands work with MySQL ado.net provider or not? I
don't see any documentation on this. I've looked at the provider code
and don't see any obvious places where parameter replacement takes
place. Here is the piece of code in question. Am I doing something
patently wrong?

I am using vs2005/c# with Ado.net driver for MySQL v5.0.3.0 and the
latest MySQL 5.0 Community Server.
static void Main(string[] args)
{
const string FIELD_FILE_ID = "@FileID";

MySqlConnection conn = new MySqlConnection("data source=localhost;user
id=root;password=root;initial catalog=testdb");
conn.Open();

MySqlCommand cmd = conn.CreateCommand();

cmd.CommandText = "SELECT files.strStoragePath FROM files WHERE
(files.numFileID = @FileID)";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@FileID", MySqlDbType.Int32);
cmd.Parameters["@FileID"].Value = 117;

DataTable dataTable = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dataTable);
da.Dispose();

if (dataTable != null)
{
if (dataTable.Rows.Count 0)
Console.WriteLine("Yeah Data");
else
Console.WriteLine("No Rows");
}
else
Console.WriteLine("Data Table does not exist");
}
Feb 6 '07 #1
1 1700
Frank Rizzo wrote:
I posted it on the mySQL forum, but no one seems to be answering
questions there.
I stand corrected. The question was answered. In case anyone is
interested, the key is to replace @ with ?

http://forums.mysql.com/read.php?38,...632#msg-138632

Regards
>
Do parameterized commands work with MySQL ado.net provider or not? I
don't see any documentation on this. I've looked at the provider code
and don't see any obvious places where parameter replacement takes
place. Here is the piece of code in question. Am I doing something
patently wrong?

I am using vs2005/c# with Ado.net driver for MySQL v5.0.3.0 and the
latest MySQL 5.0 Community Server.
static void Main(string[] args)
{
const string FIELD_FILE_ID = "@FileID";

MySqlConnection conn = new MySqlConnection("data source=localhost;user
id=root;password=root;initial catalog=testdb");
conn.Open();

MySqlCommand cmd = conn.CreateCommand();

cmd.CommandText = "SELECT files.strStoragePath FROM files WHERE
(files.numFileID = @FileID)";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@FileID", MySqlDbType.Int32);
cmd.Parameters["@FileID"].Value = 117;

DataTable dataTable = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dataTable);
da.Dispose();

if (dataTable != null)
{
if (dataTable.Rows.Count 0)
Console.WriteLine("Yeah Data");
else
Console.WriteLine("No Rows");
}
else
Console.WriteLine("Data Table does not exist");
}
Feb 6 '07 #2

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

Similar topics

4
by: Mark Wilson CPU | last post by:
A colleague has written a prototype program in PHP, using a MySQL database. It's a relatively simple app, with a restricted set of mysql commands used (see below). The MySQL DB is being replaced...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
5
by: Steven Blair | last post by:
Hi, Trying to make a connection and getting the following error: "The 'MySQLProv' provider is not registered on the local machine." MySQl is installed and working, I also went to ODBC...
2
by: Martin | last post by:
Hi, I currently have an application that connects to an MS ACCESS database. This application uses an OLEDB connection string for MS ACCESS. Now, I'd like to upsize the application so I converted...
5
by: asadikhan | last post by:
Hi, I am trying to configure my asp.net application to work with MySQL using Connector/NET and I wish to use connection pooling. What is the best way to do this? This is what I have so far: ...
2
by: zMisc | last post by:
I am using VB.NET 1.1 and cannot connect to a MySQL (v5) database. I've done the following: 1) Create a DSN for MyODBC. 2) Connect using: Driver=MySQL ODBC 3.51 Driver; Server=localhost; Data...
0
by: Tom | last post by:
Looking for some help with stored procedure call issues. Conceptually, I need to pass a data structure as the sole parameter to the Oracle stored procedure. Sounds simple enough....but how? ...
14
by: Frank Rizzo | last post by:
I've been given a project to work with which involves connecting to MySQL from .NET 2.0 app. I've googled looked and there is a metric ton of different MySQL ADO.NET providers from different...
1
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.