?
Solved

vb.net : There is no row at position 1.

Posted on 2008-11-17
3
Medium Priority
?
2,003 Views
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?

Thanks
private void SetAgreement()
    {
        DataTable dt = GetProviderAssignmentAggreementData(AssignmentId);
 
        if (dt.Rows.Count == 0)
        {
            hdn_AgreementFiledId.Value = TextBox_Sent.Text = TextBox_Received.Text = string.Empty;
 
        }
        else
        {
          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

0
Comment
Question by:Robb Hill
3 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 2000 total points
ID: 22978876
>>understand this since the value of dt.rows[0] has a value and the datatable gets populated with 1 row....

rows[1]

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...
...so when your code steps into the "else"...you're certain you have 3 rows of data?


0
 
LVL 11

Author Comment

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

Expert Comment

by:ororiole
ID: 22978925
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 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