mysql data read returning 0 rows from class

Posted by Neo on Stack Overflow See other posts from Stack Overflow or by Neo
Published on 2012-07-09T20:52:36Z Indexed on 2012/07/09 21:15 UTC
Read the original article Hit count: 173

Filed under:
|
|

I am implementing a database manager class within my app, mainly because there are 3 databases to connect to one being a local one.

However the return function isn't working, I know the query brings back rows but when it is returned by the class it has 0. What am I missing?

public MySqlDataReader localfetchrows(string query, List<MySqlParameter> dbparams = null)
    {
        using (var conn = connectLocal())
        {
            Console.WriteLine("Connecting local : " + conn.ServerVersion);
            MySqlCommand sql = conn.CreateCommand();
            sql.CommandText = query;
            if (dbparams != null)
            {
                if (dbparams.Count > 0)
                {
                    sql.Parameters.AddRange(dbparams.ToArray());
                }
            }
            MySqlDataReader reader = sql.ExecuteReader();
            Console.WriteLine("Reading data : " + reader.HasRows + reader.FieldCount);
            return reader;
            /*
            using (MySqlCommand sql = conn.CreateCommand())
            {
                sql.CommandText = query;
                if (dbparams != null)
                {
                    if (dbparams.Count > 0)
                    {
                        sql.Parameters.AddRange(dbparams.ToArray());
                    }
                }

                MySqlDataReader reader = sql.ExecuteReader();
                Console.WriteLine("Reading data : " + reader.HasRows + reader.FieldCount);

                sql.Parameters.Clear();
                return reader;
            }*/
        }

    }

And the code to get the results

query = @"SELECT jobtypeid, title FROM jobtypes WHERE active = 'Y' ORDER BY title ASC";
            //parentfrm.jobtypes = db.localfetchrows(query);
            var rows = db.localfetchrows(query);
            Console.WriteLine("Reading data : " + rows.HasRows + rows.FieldCount);
            while (rows.Read()){

            }

These scripts return the following :

Connecting local : 5.5.16
Reading data : True2
Reading data : False0

© Stack Overflow or respective owner

Related posts about c#

Related posts about mysql