MyDataSet.Designer.cs throws {"There is no row at position 0."} even though I made sure there is data?

36 Views Asked by At

This is the code snippet where the exception is thrown

 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
    
        productCardTableAdapter.Fill(_MyInv_Data_DataSet.ProductCard);
        flowLayoutPanel1.Controls.Clear();
    if (_MyInv_Data_DataSet.ProductCard.Rows.Count > 0)
    {
        foreach (DataRow r in _MyInv_Data_DataSet.ProductCard.Rows)
        {
            CustomCard c = new CustomCard();
            c._ID = int.Parse(r["ID"].ToString()); //the exception is thrown after this statement
            flowLayoutPanel1.Controls.Add(c);
        }
    }
}

you clearly see that I checked that the rows are not empty and the fact the error is thrown after entering the foreach statement is another proof as well. the error is thrown in the MyDataSet.Designers.cs at the following code

public ProductCardRow this[int index] {
    get {
        return ((ProductCardRow)(this.Rows[index]));//here
    }
}

I put a breakpoint just after the entry of the foreach and the DataRow r has correct values as well so idk what is the problem? as for the "this.Rows[index]"it showed that the rows count is 0.

I just wanted to create an instance of my custom component whenever a new Product is added.

I tried changing the Syntax here and it showed the correct ID

But It still shows the same error and shows that the rows are empty

0

There are 0 best solutions below