Kep Deep
asked on
Can anyone help me fix a InvalidCastException on VS windows forum C#
An unhandled exception of type 'System.InvalidCastExcepti on' occurred in mscorlib.dll
Additional information: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'.
Additional information: Unable to cast object of type 'System.Data.DataRowView' to type 'System.IConvertible'.
private void listgames_Click(object sender, EventArgs e)
{
DataRow drgameshop;
int rowNo;
rowNo = Convert.ToInt32(lstgames.SelectedValue); //THIS IS WHERE THE ERROR OCCURS
drgameshop = dscategory.Tables["Category"].Rows.Find(rowNo);
lblCN.Text = drgameshop["Category.CategoryNo"].ToString();
lblSN.Text = drgameshop["Stock.StockNo"].ToString();
lblSD.Text = drgameshop["StockDesc"].ToString();
lblQ.Text = drgameshop["Qty"].ToString();
lblCP.Text = drgameshop["CostPrice"].ToString();
lblSP.Text = drgameshop["SellingPrice"].ToString();
lblRL.Text = drgameshop["ReOrderLevel"].ToString();
lblRQ.Text = drgameshop["ReOrderQty"].ToString();
lblSupNo.Text = drgameshop["Supplier.SupplierNo"].ToString();
lblON.Text = drgameshop["OrderDetail.Orderno"].ToString();
lblQO.Text = drgameshop["QtyOrdered"].ToString();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That is great, have a nice day.
The solution was not more than to explain the error message and give a hint that the type of the variable listgames might be wrong. As the Author was able to solve the issue by pursuing the hints, the question can be normally closed with an equal split.
Sara
Sara
ASKER