i am getting error "Unable to cast object of type System.data.datatable to type ReceiveproductDetailsDatatable" while trying to convert system.data.datatable to typed dataset.datatable.
I have created a strongly typed dataset with datatable ProductDetails. The declaration is as below.
ReceiveProducts.ReceiveProductDetailsDataTable ProductDataTbl = new ReceiveProducts.ReceiveProductDetailsDataTable(); I getting the product details from database and i want to put this in session for editing.
I getting the product details from database and i want to put this in session for editing.
DataSet dsReceive = new DataSet();
dsReceive = objBZ.GetReceiveViewDetails(ReceiveListID);
DataTable dt = new DataTable();
ProductDataTbl = (ReceiveProducts.ReceiveProductDetailsDataTable)dt;
The above statement gives error "Unable to cast object of type System.data.datatable to type ReceiveproductDetailsDatatable" while trying to convert system.data.datatable to typed dataset.datatable "
Session["Products"] = ProductDataTbl;
How should i do the casting to avoid this error?
Hi,
Your code doesn't make any sense. You have not assigned the object dt in the code.
Suren.
You cannot cast a more generic object into a more specific object when it is in reality not. When an instance of the Animal class is instantiated, its memory structure is not complete enough to make it properly represent a Rabbit object.
You can cast a ReceiveProductDetailsDataTable into a DataTable, but not a DataTable into a ReceiveProductDetailsDataTable. That can only be done if the actual DataTable object being referenced is indeed the more-specific instance ReceiveProductDetailsDataTable.
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral