Doudy

Doudy

  • NA
  • 11
  • 18.9k

Unable to cast object of type 'System.Data.DataRow' to type

Jan 3 2013 11:28 AM
I received the error:"Unable to cast object of type 'System.Data.DataRow' to type 'System.Data.DataRowView"

private void addToOrder(DataRowView drv)
{
DataRow dr = orderDataTable.NewRow(); 
dr["ProductID"] = drv["ProductID"];
dr
["ProductBarcode"] = drv["ProductBarcode"];
dr
["ProductName"] = drv["ProductName"];
dr["SalePrice"] = drv["SalePrice"];
dr
["SoldQuantity"] = 1;
dr
["NotEditable"] = false;
try
{
orderDataTable.Rows.Add(dr);
}
catch (ConstraintException)
{
DataRow dr1 = orderDataTable.Rows.Find(drv["ProductID"]); dr1["SoldQuantity"] = Convert.ToInt32(dr1["SoldQuantity"]) + 1;
}
}


private
void btnAddToOrder_Click(object sender, RoutedEventArgs e)
{

// add to order
if(txtBarcodeAuto.Text.Length >0)
{
DataTable dscrntProd = prods.SelCrntProd4Sale(crntProdID);//get data from sql server database for product details(productID, ProductName,ProductPrice)
foreach (DataRowView dr in dscrntProd.Rows)
{
addToOrder
(dr);
}
}
} 

Any help Most Appreciated
Thanks.

Answers (1)