我收到错误:
无法将“System.Data.DataRow”类型的对象转换为“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)
{
//get data from sql server database for product details(productID, ProductName,ProductPrice)
DataTable dscrntProd = prods.SelCrntProd4Sale(crntProdID);
foreach (DataRowView dr in dscrntProd.Rows)
{
addToOrder(dr);
}
}
}