Missing first record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using asp.net and .net framework 2 and SQL server 2000
I am using simple SELECT statement in SP to retrieve data and then bind to a
datagrid but fail to pick up the first record in the dataset:

invConn = New
SqlConnection(ConfigurationManager.ConnectionStrings("Connectstring").ConnectionString)
invConn.Open()
invComm = New SqlCommand(zStrg, invConn)
invComm.CommandType = Data.CommandType.StoredProcedure
invComm.Parameters.AddWithValue("@ClCode", strClCode)
iP = invComm.ExecuteReader
iP.Read()
dgPInv.DataSource = iP
dgPInv.DataBind()
iP.Close()
invConn.Close()

The SP is pulling back the full dataset but code above misses first rec.
with thanks
 
Remove

iP.Read()

before binding the DataReader to the grid; In the grid's DataBind() method,
a loop is made to call the DataReader's Read() method until DataReader's
end.

If you called Read() before DataBind(), of course the first row would be
missed, since DataReader is read only and forward only.
 
Back
Top