Hi learning-4983,
You did not check whether your DataTable contains any content. The message indicates that there is no row at position 0.
So you need to verify that rows exist before attempting to get data from them.
dt = course.getCourseById(id);
if (dt.Rows.Count > 0)
{
txtLabel.Text = dt.Rows[0][1].ToString();
txthours.Text = Convert.ToInt32(dt.Rows[0][2]).ToString();
txtDesc.Text = dt.Rows[0][3].ToString();
}
else
{
// Handle missing data in an appropriate way...
}
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.