Idatareaders not returning values from database
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")
开发者_StackOverflow中文版 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.
Try removing the
reader.Read()
line from SelectDepartmentID.
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.
精彩评论