Idatareaders 不从数据库返回值

发布于 2024-09-03 12:45:32 字数 885 浏览 1 评论 0原文

在我的代码隐藏中,我有这个 vb:

 Dim reader as idatareader = includes.SelectDepartmentID(PageID)
        While reader.Read
            Did = reader("departmentid")
            GroupingHeading = reader("heading")
            Folder = reader("folder")
            If reader("OwnBanner") Is DBNull.Value Then
                OwnBanner = String.Empty
            Else
                OwnBanner = reader("ownbanner")
            End If

然后在我的班级中,我有:

 Public Function SelectDepartmentID(ByVal PageID As Integer) As IDataReader
        Dim Command As SqlCommand = db.GetSqlStringCommand("sql")
        db.AddInParameter(Command, "@pageid", Data.DbType.Int32, PageID)
        Dim reader As IDataReader = db.ExecuteReader(Command)
        reader.Read()
        Return reader
    End Function

没有出现任何错误,但读者没有返回任何内容。我的代码有错误吗?

谢谢。

In my codebehind I have this vb:

 Dim reader as idatareader = includes.SelectDepartmentID(PageID)
        While reader.Read
            Did = reader("departmentid")
            GroupingHeading = reader("heading")
            Folder = reader("folder")
            If reader("OwnBanner") Is DBNull.Value Then
                OwnBanner = String.Empty
            Else
                OwnBanner = reader("ownbanner")
            End If

Then in my class I have:

 Public Function SelectDepartmentID(ByVal PageID As Integer) As IDataReader
        Dim Command As SqlCommand = db.GetSqlStringCommand("sql")
        db.AddInParameter(Command, "@pageid", Data.DbType.Int32, PageID)
        Dim reader As IDataReader = db.ExecuteReader(Command)
        reader.Read()
        Return reader
    End Function

No Errors are being presented yet nothing is being returned by the reader. Is there an error in my code?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-小熊_ 2024-09-10 12:45:32

尝试

reader.Read()

从 SelectDepartmentID 中删除该行。

Try removing the

reader.Read()

line from SelectDepartmentID.

谜兔 2024-09-10 12:45:32

您正在跳过阅读器的第一行。删除 SelectDepartmentID 函数中 return 语句之前的 reader.Read() 语句。

任何返回 reader 的函数都不应该假设调用代码将用它做什么,而应该不加修改地返回它。

You are skipping the first row of the reader. Remove the reader.Read() statement in the SelectDepartmentID function just prior to the return statement.

Any function that returns a reader should make no assumptions about what the calling code will do with it and just return it unmodified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文