Convery DataTable to Strongly typed dataset.

Posted on 2004-11-16
Last Modified: 2012-06-21
I have a problem, whne i try to convert a standard DataTable object to a Strongly typed DataTable  (Datatable belongs to a strongly typed dataset) and both tables have the same schema. here is the code the code:

TypedDataSet.TypeDataTable ResultTable = (TypedDataSet.TypeDataTable)GetStandartTable(MySqlString);

I get  " Specified cast is not valid."

any idea on how can i convert or even copy all the info between the two tables?
Question by:saturn_one
    1 Comment
    LVL 20

    Accepted Solution

    Well, your original table is of type DataTable and you are trying to cast the type, which is a problem with type casting. The fact that the two tables have the same schema is irrelevant.

    What you can do is copy all data, but this will be a slow operation. The code would be:

    TypedDataSet.TypeDataTable ResultTable = new TypedDataSet.TypeDataTable();
    foreach (DataRow row in GetStandartTable(MySqlString))
        ResultTable.ImportRow (row);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now