First record of datagrid not showing

E

Edward Harford

First record in grid is not showing having been called from stored proc.
Grid shows rest of records with no problem. (Using DataReader)
Any thoughts? Many thanks
EdwardH
 
S

Steven Cheng[MSFT]

Hi Edward,

From your description, you used the DataReader to retrieve some records
from database and bind them in a webform datagrid so as to populate in a
webform page. But you found that everytime the displayed grid will lose the
first record, yes?

As for this problem, I think we can first perform the following things:
1. What's the back DBserver you're using? SQlServer or anyother ? If
SQLserver, you can try running the stored procedure in the QueryAnalyzer
tool first to see whether it really return back all the correct records.
Also, you can do a manually loop on the DataReader and try printout all the
records in page's output (rather than bind to datagrid ) to confirm this.

2.If the SP and DataReader really return the correct data records, we
should do further throubleshoot on the datagrid's binding code. I think you
can add some break points in the datagrid's ItemDataBound event since each
time a record is bind to a gridline, the event will be fired, so that you
can see whether the first record is actually binded or not.

If you have any other findings, please also feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
E

Edward Harford

Steven
It is SQL Server and I can run stor proc within Query Analyser with no
problem.
Could you elaborate on how to manually loop tru bound records? How I am not
sure how to use the ItemDataBound event.
Code:
invConn = New SqlConnection(ConnectString)
invConn.Open()
invCopp = New SqlCommand("zPart", invConn)
invCopp.CommandType = CommandType.StoredProcedure
invCopp.Parameters.Add("@InventNo", Me.iInventNo.Text)
iPt = invCopp.ExecuteReader
iPt.Read()
dgPart.DataSource = iPt
dgPart.Databind()
iPt.Close()
invConn.Close()

With thanks
EdwardH
 
S

Steven Cheng[MSFT]

Hi Edward,

Thanks for your response. From the detailed code you provided, I found that
the problem is caused by the
"iPt.Read()" method you called after the command's ExecuteReader and bind
the reader to datagrid. The "Read" method make the cursor in the DataReader
move to the next record and when the datagrid loop through the datareader
internally it will lose the first record. So please comment the
"iPt.Read()" line between the following code to see whether it helps.
Thanks.
==================
iPt = invCopp.ExecuteReader
iPt.Read()
dgPart.DataSource = iPt
===============

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
E

Edward Harford

Steven
Many thanks - that works fine - effectively my code is trying to read
twice!!
EdwardH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top