Groups | Blog | Home
all groups > dotnet ado.net > october 2007 >

dotnet ado.net : Missing first record



EdwardH
10/28/2007 3:26:00 PM
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
Norman Yuan
10/28/2007 10:49:27 PM
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.


[quoted text, click to view]

AddThis Social Bookmark Button