First record of datagrid not showing

Discussion in 'ASP .Net Datagrid Control' started by Edward Harford, Jul 20, 2004.

  1. 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
     
    Edward Harford, Jul 20, 2004
    #1
    1. Advertising

  2. 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
     
    Steven Cheng[MSFT], Jul 21, 2004
    #2
    1. Advertising

  3. 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]" <> 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
    >
     
    Edward Harford, Jul 21, 2004
    #3
  4. 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
     
    Steven Cheng[MSFT], Jul 22, 2004
    #4
  5. Steven
    Many thanks - that works fine - effectively my code is trying to read
    twice!!
    EdwardH
    "Steven Cheng[MSFT]" <> 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
    >
     
    Edward Harford, Jul 22, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Booysen
    Replies:
    2
    Views:
    663
    Ray Booysen
    Mar 28, 2006
  2. Replies:
    3
    Views:
    985
    Mark Parnell
    Oct 14, 2005
  3. Guest
    Replies:
    7
    Views:
    700
    Walter Wang [MSFT]
    Jun 28, 2006
  4. Josh Behl
    Replies:
    3
    Views:
    137
    Imtiaz Hussain
    Oct 29, 2003
  5. Arbajram

    Showing only first part of the field in datagrid

    Arbajram, Jun 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    120
    Arbajram
    Jun 17, 2004
Loading...

Share This Page