问题
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