Oracle DataReader returns 1 row but Read method returns false

ぃ、小莉子 提交于 2019-12-24 18:18:45

问题


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>
          }
       }

回答1:


Try:

if (myReader.HasRows)
  while (myReader.Read())
  .....


来源:https://stackoverflow.com/questions/2199877/oracle-datareader-returns-1-row-but-read-method-returns-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!