Question

I have a basic sql statement that looks up a user and returns one record but when I run a block of code that says if(myReader.Read()) it returns false. I have stepped through the code and examined the reader object and it does in fact contain one record. below is the code.

sql: SELECT user_name, user_password, user_state FROM users WHERE users.user_id = 123

    System.Data.Common.DbCommand _cmd = this.GetCommand(conn, _dbf, sqlText, CommandType.Text);
     System.Data.Common.DbConnection _cn = _cmd.Connection;
     System.Data.Common.DbDataReader myReader = null;

     _cn.Open();
     using(_cn) {
        myReader = _cmd.ExecuteReader();
        if (myReader.Read())  {
                <object gets built here with user data returned from sql>
          }
       }
Was it helpful?

Solution

Try:

if (myReader.HasRows)
  while (myReader.Read())
  .....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top