Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-09-2009
Member
 
Join Date: Nov 2008
Posts: 94
How to manage Parameterized Queries in MySQL

I'm using MySQL with the MyODBC driver. But MySQL is tricky, it doesn't support named parameters, so you have to use a question mark and add parameters in the right order. To connect to MySQL database you can use the System.Data.Odbc namespace in .net. If I remove them and just explicitly put in the data I'm looking for the datareader works, however doing as I have below returns no results in the datareader.
Reply With Quote
  #2  
Old 24-09-2009
Member
 
Join Date: Dec 2008
Posts: 202
Re: How to manage Parameterized Queries in MySQL

If your database is so poor that it doesn't support parameterized queries, You should look into using the ByteFX MySQL library. It's a native MySQL interface for .NET, so you don't have to use ODBC or ODBC drivers. you might want to build your own format() style function that replaces $values in your query.That seems to be working earlier in your code. Are you sure there is a value to read there (i.e. is your query returning 0 rows or null or something else that can't be converted to a string?)
Reply With Quote
  #3  
Old 24-09-2009
Member
 
Join Date: Dec 2008
Posts: 93
Re: How to manage Parameterized Queries in MySQL

Looks like that procedure works fine on the line account1Name = r.GetValue(0).ToString();. Maybe you want to check the return value of r.Read() to see if there are any rows first. You should look into using the ByteFX MySQL library. It's a native MySQL interface for .NET, so you don't have to use ODBC or ODBC drivers.
Reply With Quote
  #4  
Old 24-09-2009
Member
 
Join Date: Nov 2008
Posts: 48
Re: How to manage Parameterized Queries in MySQL

Coming from SQL Server and Oracle, It looks like you're trying to get a single value out of a query. You might want to look into the ExecuteScalar() method instead of ExecuteReader(). I was so used to using named parameters that I totally forgot the questionmark approach. This being my first MySQL project, I was about to knock my head through the wall wondering why that database wasn't accepting my update statements.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to manage Parameterized Queries in MySQL"
Thread Thread Starter Forum Replies Last Post
How to manage databases and tables in MySQL? Aahlaadith Software Development 5 17-12-2010 07:18 AM
Optimizing queries in MySQL Caden Fernandes Software Development 4 05-03-2010 07:14 PM
How to Run MySQL Queries with PHP? Rob Dizzle Software Development 4 05-02-2010 05:40 AM
Show Number of MySQL Queries Jagriti Software Development 3 28-07-2009 03:17 PM
Need to have multiple where queries in MySQL query Anti_Trend Software Development 1 03-07-2009 10:17 PM


All times are GMT +5.5. The time now is 08:28 PM.