Query of Tables always returns count=0 from MySQL Database using ASP.NET 2005

asp.net , db , mysql United States
  • 12 years ago
    I am encountering an odd issue where no matter what data I query from my MySQL database via ASP.NET [2005] I always get back a count of 0... To start off, I open the MySQL 5.1 Command Line Client, enter my password ("pass") and then select my database (USE bank;). From here I do a the following query: SELECT * FROM employees; And it returns 18 rows of results (as expected). Now in my application (for which I installed the "MySQL Connector Net 5.1.6" which should work with ASP.NET 2005 right?) I added the reference and code (as seen below) to try and mimic the exact same thing as I did manually above. However in this case the result (count of dataset ds) is always 0... [Code] MySqlConnection m_MySqlConnection = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ToString()); m_MySqlConnection.Open(); System.Data.DataSet ds = new System.Data.DataSet(); MySqlDataAdapter mysqlDA = new MySqlDataAdapter("SELECT * FROM employees;", m_MySqlConnection); mysqlDA.Fill(ds); m_MySqlConnection.Close(); return ds; [/Code] I checked "m_MySqlConnection" and the STATE is open (so I assume it connected properly to my database - therefore not a problem with the connection string and/or authentication correct?) but no matter what my ds has a count = 0...?...? I was doing some reading and some people needed to add a user with permissions to allow the ASP page to connect to the database - I didn't do that but I assume if there was a problem with that I wouldn't be able to connect and my STATE wouldn't be open... At this point I am a little lost as to what I could be missing/forgetting... Any help would be greatly appreciated... Thanks,
  • 12 years ago

    Hi,

    I havent used MySQL with asp.net before, but i did when i developed in PHP.  I remember there was a nuance with MySQL connectors that didnt return a row count, so you could never tell how many rows you had returned unless you looped and counted them.

    While not always possible, i development my SQLs to always have a count column, using like count(*) so i could look at this column and workout how many rows i had been returned from MySQL.

    I dont know if someone else has found a connector that can count rows correctly from MySQL?

    Si

  • 12 years ago
    So - does that mean that even though Count=0 there is acctually still data in the Data in DataSet?
  • 12 years ago

    Hi,

    You can always set a break point on your code and the view the dataset after you have populated it, it will show you what data you have in there.

    Out of interest, are you using a datareader to get your data or filling a dataset?

    The bug i mentioned replied to the equivalent of a datareader, not sure what it will be like for a dataset.

    Si

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra