Solved

Casting a DataSet to be a Typed DataSet

Posted on 2004-04-21
1
741 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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