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

Re: Missing first record by Norman

Norman
Sun Oct 28 15:49:27 PDT 2007

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.


"EdwardH" <EdwardH@discussions.microsoft.com> wrote in message
news:3E2EABDC-24E1-42F3-8DB1-FB0CCD685666@microsoft.com...
> 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
>