Link to home
Start Free TrialLog in
Avatar of Kep Deep
Kep Deep

asked on

Can anyone help me fix a InvalidCastException on VS windows forum C#

An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll

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();
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kep Deep
Kep Deep

ASKER

Thanks for the responses. I managed to fix the problem "kinda". I was using too many tables just when i should of been using one table for this forum. Its working fine now.
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