Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Casting a DataSet to be a Typed DataSet

Posted on 2004-04-21
1
Medium Priority
?
744 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

610 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