Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:57:51+00:00 2026-05-26T12:57:51+00:00

I have a winforms app that uses a strongly typed custom DataSet for holding

  • 0

I have a winforms app that uses a strongly typed custom DataSet for holding data for processing. It gets populated with data from a database.

I have a user control that takes any custom dataset and displays the contents in a data grid. This is used for testing and debugging. To make the control reusable, I treat the custom dataset as a normal System.Data.DataSet.

I have extended the control to allow the dataset to be saved to an XML file and also load previously saved XML files.

What I’m now trying to do is take the loaded data file, which is treated as a standard DataSet, and cast it back to the Custom Dataset. This shouldn’t be difficult but I am getting the following System.InvalidCastException message:

Unable to cast object of type ‘System.Data.DataSet’ to type
‘CostingDataSet’.

Here is an example of the problem code (It’s the last line of the 3 that generates the exception):

DataSet selected = debugDisplay.SelectedDataSet;

CostingDataSet tempDS = new CostingDataSet();
tempDS = (CostingDataSet)selected.Copy();

Can anyone give me a steer on how to fix this?

Edit:
Following the comments from nEM I implemented this and all was good.

foreach (System.Data.DataTable basicDT in selected.Tables)
{
    DataTable dt = tempDS.Tables[basicDT.TableName];
    dt = basicDT.Copy();
}

In addition, the code suggested by SSarma also works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:57:51+00:00Added an answer on May 26, 2026 at 12:57 pm

    From what I have gathered from this website, you can’t cast a regular dataset into a typed one which makes sense as its strongly typed and has certain specifications. If you have saved it as a regular dataset, when you deserialise it, the XML has no recollection of it ever being created as a typed dataset. For the xml file, you only ever saved a regular dataset so it is equivalent to trying to convert a standard dataset into a typed one by explicit casting which isn’t allowed.

    You could create a populate method that takes in a regular dataset as an argument which copies all the data into your typed dataset.

    This is assuming that you are serialising it as a standard dataset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So we have a winforms app that in the task manager should anywhere from
I have a winforms app that uses a UserControl. The user control's job is
I have a WinForms app that uses the Settings feature of .NET 2, but
I have a .NET 4 WinForms app that uses the ADO.NET Entity Framework. Some
We have a huge client/server WinForms app that uses .NET remoting to pass DAOs
I have a Winform App that uses a 3rd Party Library of Controls, DevExpress.
I have a CRUD winform App that uses Merge Replication to allow disconnected functionality.
We have a WinForms app that runs fine on x86, but has many third-party
I have a Winforms app that has a DataGridView that is databound at runtime.
I have a winforms app that checks user credentials as it starts. If autharization

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.