Solved

Casting a DataSet to be a Typed DataSet

Posted on 2004-04-21
1
738 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
ID: 10878665
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Single Form 8 42
Reading the Web.Config using IIS 7.5? 4 36
C# winforms programmitically move panels 6 29
Call Controller Action Method from ASPX 2 14
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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