Solved

Casting a DataSet to be a Typed DataSet

Posted on 2004-04-21
1
740 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set custom font WPF 2 24
Problem to copy file 14 88
parsing question on dynamic concatenation 3 39
c#  FTP ftpwebrequest URI invalid 6 44
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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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