We help IT Professionals succeed at work.
Get Started

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

Kep Deep
Kep Deep asked
on
239 Views
Last Modified: 2017-03-26
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

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE