Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > First record of datagrid not showing

Reply
Thread Tools

First record of datagrid not showing

 
 
Edward Harford
Guest
Posts: n/a
 
      07-20-2004
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



 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-21-2004
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

 
Reply With Quote
 
 
 
 
Edward Harford
Guest
Posts: n/a
 
      07-21-2004
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
"Steven Cheng[MSFT]" <v-> wrote in message
news:...
> 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
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-22-2004
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

 
Reply With Quote
 
Edward Harford
Guest
Posts: n/a
 
      07-22-2004
Steven
Many thanks - that works fine - effectively my code is trying to read
twice!!
EdwardH
"Steven Cheng[MSFT]" <v-> wrote in message
news:...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I'm lazy: how do I make the first databound record not display/chop off the first element from SqlDataSource ASP .Net 7 06-28-2006 10:24 AM
ASP 1.1: DataGrid - Showing/Not Showing Buttons Ray Booysen ASP .Net 2 03-28-2006 02:49 PM
Showing only first part of the field in datagrid Arbajram ASP .Net Datagrid Control 2 06-17-2004 08:11 AM
" Invalid Disk Table in Boot Record - Boot Record could not be repaired " reply@newsgroup.please Computer Support 2 12-01-2003 05:37 AM
All my drop down lists get reset to the first value when I go in to edit a record in the datagrid.... Josh Behl ASP .Net Datagrid Control 3 10-29-2003 05:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57