Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 854
  • Last Modified:

Convery DataTable to Strongly typed dataset.

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?
0
saturn_one
Asked:
saturn_one
1 Solution
 
TheAvengerCommented:
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);
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now