Solved : There is no row at position 1.

Posted on 2008-11-17
Last Modified: 2012-06-27
The following line of code in the attached function crashes with the error "There is no row at position 1"
TextBox_Sent.Text= dt.Rows[1]["Sent"].ToString();

I do not understand this since the value of dt.rows[0] has a value and the datatable gets populated with 1 row....

Any ideas..why this crashes?

private void SetAgreement()


        DataTable dt = GetProviderAssignmentAggreementData(AssignmentId);

        if (dt.Rows.Count == 0)


            hdn_AgreementFiledId.Value = TextBox_Sent.Text = TextBox_Received.Text = string.Empty;




          hdn_AgreementFiledId.Value = dt.Rows[0]["AgreementFiledID"].ToString();

          TextBox_Sent.Text= dt.Rows[1]["Sent"].ToString();

          TextBox_Received.Text = dt.Rows[2]["Received"].ToString();



Open in new window

Question by:Robb Hill
    LVL 37

    Accepted Solution

    >>understand this since the value of dt.rows[0] has a value and the datatable gets populated with 1 row....


    would actually be the second row of data since the index starts at zero...if your datatable is populated with 1 row, then there is only rows[0] available to reference... when your code steps into the "else"'re certain you have 3 rows of data?

    LVL 11

    Author Comment

    by:Robb Hill
    duh..thanks..idiot moment:)
    LVL 16

    Expert Comment

    The datatable index starts at zero. So the first row goes into Rows[0]. You said you are only getting one row so there is no row to put into Row[1], which would be the second row.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now