SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Converting System.data.datatable to typed dataset.datatable.

Latest post 02-05-2008 4:19 PM by icelava. 2 replies.
  • 01-09-2008 11:09 AM

    Converting System.data.datatable to typed dataset.datatable.

    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.

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

    DataSet dsReceive = new DataSet();

    dsReceive = objBZ.GetReceiveViewDetails(ReceiveListID);

    DataTable dt = new DataTable();

    DataTable dt = new DataTable();

    ProductDataTbl = (ReceiveProducts.ReceiveProductDetailsDataTable)dt;

    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;

    "Products"] = ProductDataTbl;

     

    How should i do the casting to avoid this error?

  • 02-05-2008 1:38 PM In reply to

    • Sur3ndEr
    • Top 500 Contributor
    • Joined on 12-11-2007
    • Singapore
    • Posts 4

    Re: Converting System.data.datatable to typed dataset.datatable.

    Hi,

     Your code doesn't make any sense. You have not assigned the object dt in the code.

     Suren.

  • 02-05-2008 4:19 PM In reply to

    Re: Converting System.data.datatable to typed dataset.datatable.

    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

Page 1 of 1 (3 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems