Results 1 to 4 of 4

Thread: How to manage Parameterized Queries in MySQL

  1. #1
    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.

  2. #2
    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?)

  3. #3
    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.

  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,573,655.37214 seconds with 17 queries