Idatareaders 不从数据库返回值
在我的代码隐藏中,我有这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
从 SelectDepartmentID 中删除该行。
Try removing the
line from SelectDepartmentID.
您正在跳过阅读器的第一行。删除
SelectDepartmentID
函数中 return 语句之前的reader.Read()
语句。任何返回 reader 的函数都不应该假设调用代码将用它做什么,而应该不加修改地返回它。
You are skipping the first row of the reader. Remove the
reader.Read()
statement in theSelectDepartmentID
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.