Extracting a row out a dataset and working with it

  • Thread starter Thread starter Cdude
  • Start date Start date
C

Cdude

1 public void AddItem(string itemCode)
2 {
3 DataRow[] itemRow = DBAdmin.Products.Select("Code =
'"+itemCode+"'");
4 addItemRow["Code"] = itemRow[0]["Code"].ToString();
5 addItemRow["Amount"] = itemRow[0]
["SellPriceIn"].ToString();
6 addItemRow["Vat"] = itemRow[0]["Vat"].ToString();
7 addItemRow["Qty"] = 1;
8 addItemRow["DocNo"] = 2;
DBAdmin.DLitem.Rows.Add(addItemRow);
}
This my code and this is the error i get on line 4

"Index was outside the bounds of the array"

Any suggestions ? on what i am doing wrong
 
Cdude said:
1 public void AddItem(string itemCode)
2 {
3 DataRow[] itemRow = DBAdmin.Products.Select("Code =
'"+itemCode+"'");
4 addItemRow["Code"] = itemRow[0]["Code"].ToString();
5 addItemRow["Amount"] = itemRow[0]
["SellPriceIn"].ToString();
6 addItemRow["Vat"] = itemRow[0]["Vat"].ToString();
7 addItemRow["Qty"] = 1;
8 addItemRow["DocNo"] = 2;
DBAdmin.DLitem.Rows.Add(addItemRow);
}
This my code and this is the error i get on line 4

"Index was outside the bounds of the array"

Any suggestions ? on what i am doing wrong

Check itemRow.Count to see if there's even any records found by your select. The
error you're getting would seem to indicate there are no entries in the itemRow
array.

Chris.
 
1 public void AddItem(string itemCode)
2        {
3            DataRow[] itemRow = DBAdmin.Products.Select("Code =
'"+itemCode+"'");
4           addItemRow["Code"] = itemRow[0]["Code"].ToString();
5            addItemRow["Amount"] = itemRow[0]
["SellPriceIn"].ToString();
6            addItemRow["Vat"] = itemRow[0]["Vat"].ToString();
7            addItemRow["Qty"] = 1;
8            addItemRow["DocNo"] = 2;
            DBAdmin.DLitem.Rows.Add(addItemRow);
       }
This my code and this is the error i get on line 4

"Index was outside the bounds of the array"

Any suggestions ? on what i am doing wrong

Are you sure that you are getting at least one row?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top