I'm having an issue with a data reader skipping the first returned record. I've double checked the SQL statment and I know it is actually skipping the first record.
I noticed that if I remove the "If dataReader.Read Then..." statement from around my data bind, it works, but then I can't set the label when no records show up.
Here's the code, any help would be appreciated.
KizMar
------------
I noticed that if I remove the "If dataReader.Read Then..." statement from around my data bind, it works, but then I can't set the label when no records show up.
Here's the code, any help would be appreciated.
Code:
Private Function FillHistoryGrid(ByVal studentID)
' Pulling all history records for this week & this studentID
sqlQuery = "..."
' Execute command
myConnection.Open()
Dim myCommand As New SqlCommand(sqlQuery, myConnection)
dataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
If dataReader.Read Then
' Bind selected data to the gridview
Me.gvMealHistory.DataSource = dataReader
Me.gvMealHistory.DataBind()
Else
Me.lblGridMessage.Text = "No records found."
End If
' Close connection stuff
dataReader.Close()
myConnection.Close()
End Function
KizMar
------------