c# - 检查它是否是sqldatareader中的最后一条记录

标签 c# sql sqldatareader

有没有办法检查我是否在最后一条记录中? 谢谢

最佳答案

使用此模式识别和处理结果中的最后一行:

if (reader.Read())
{
    var loop = true;
    while (loop)
    {
        //1. Here retrive values you need e.g. var myvar = reader.GetBoolean(0);
        loop = reader.Read();
        if (!loop)
        {
            //You are on the last record. Use values read in 1.
            //Do some exceptions
        }
        else {
            //You are not on the last record.
            //Process values read in 1., e.g. myvar
        }
    }
}

关于c# - 检查它是否是sqldatareader中的最后一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11703305/

相关文章:

服务堆栈 OrmLite : Capture PRINT statements from stored procedure

c# - 从文件中动态读取资源

c# - 反序列化具有未知字段的 JSON

mysql - 如何在没有工作台的情况下将 .mwb 转换为 .sql

php - 将多维数组简化为线性数组

c# - SqlDataReader "Enumeration yielded no results"

C# with System.Data.SQLite - 关闭连接

c# - 显示启动画面导致 InvalidOperationException

mysql - SQL查询多年的日期范围

c# - MAX(id) 使用 SqlDataReader C#