views:

18

answers:

2

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.

+2  A: 

Try removing the

reader.Read()

line from SelectDepartmentID.

Russ C
+1  A: 

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.

Quick Joe Smith