Solved

Casting a DataSet to be a Typed DataSet

Posted on 2004-04-21
1
737 Views
Last Modified: 2012-05-04
I have a typed dataset.  I want to instantiate a untyped dataset and cast it to be the typed dataset. I have my example below

MyTypedDataset mtd = new MyTypedDataSet();     //this is an instance of my typed dataset

// Let's assume that I have a connection and SqlDataAdapter

mySqlDataAdapter.fill(mtd ,"Employees");   //I'm filling my dataset with records from employees table

//Now, I would like just instantiate a dataset and cast the typed dataset back to be just a dataset

DataSet myDataset = new DataSet();
myDataSet = (DataSet)mtd;


For some reason, it still sees it as a typed dataset.  Can someone explain

Thanks,



0
Comment
Question by:tinman1412
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
Comment Utility
Typed Dataset is derived from DataSet. The  following lines:

DataSet myDataset = new DataSet();
myDataSet = (DataSet)mtd;

are not 100% correct. First line creates new untyped dataset, and second sets myDataSet as second reference to mtd. Reference to untyped DataSet created in the first line is lost, and both variables point to the same typed DataSet.

However, if you want to work with typed DataSet as with untyped, you can do this both with original mtd variable and with myDataSet variable. Since MyTypedDataset is derived from DataSet, all DataSet functions are available.
0

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
reading json from C# REST service 1 48
What are the big features of MVC5? 4 49
XML to SQL Table using c# 5 42
c# code 19 55
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

14 Experts available now in Live!

Get 1:1 Help Now