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

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

LVL 11
Robb HillSenior .Net DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robb HillSenior .Net DeveloperAuthor Commented:
duh..thanks..idiot moment:)
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.