我有一个问题,阅读器似乎表明它具有来自返回的 SQL 的行,但阅读器的 while 循环从未运行。我在 reader.hasrows 中放了一个消息框作为验证,我也在 while 循环之后的第一行放了一个消息框。hasrows 的消息框已执行,但 Read 的消息框未执行。这是非常令人费解的。我尝试了对数据库的查询,它确实返回了行。这是代码片段。
using (DbConnection connection = CADBase.DbProviderFactory.CreateConnection())
    {
        connection.ConnectionString = CADBase.DbConnectionString;
        connection.Open();
        using (DbCommand command = connection.CreateCommand())
        {
            SQL = <statement here>;
            command.CommandText = SQL
            using (DbDataReader reader = command.ExecuteReader())
            {
                    while (reader.Read())
                    {
            //NEVER MAKES IT HERE
                    } 
    }
        }
    }