Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

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?

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

ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robb Hill

ASKER

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.