473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strongly typed Datasets and explicit cast..

Hi,

I have a general all purpose class that can take the name of a stored
procedure and return a dataset...

This general dataset that is returned I wish to cast to a strongly typed
dataset of my choosing.
I have the XML Schema and a generated specialization of the DataSet that I
wan´t to cast to...

Generated by xsd.exe
public class MyStronglyTypedDS : DataSet {
....
}

My app code: (wich causes Invalid Cast Exception...)

MyStronglyTypedDS ds = (MyStronglyTypedDS) obj.GetDataSet("MyStoredProc");
My DAL code:

public DataSet GetDataSet(string sproc) {
....
return ds;
}

I would rely appreciate some feedback!
Thanks

/Oscar
Nov 15 '05 #1
2 4240
Oscar,

You can not do this. What you have to do is get the contents of the
dataset into some other medium (string, stream, file, etc, etc), and then
create a new instance of your typed dataset. Once you have that, you should
be able to load the contents of the other dataset in that medium (using
ReadXml, most likely), and then it will populate the new typed dataset
appropriately.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oscar Thornell" <os***@cyberode.se> wrote in message
news:up**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have a general all purpose class that can take the name of a stored
procedure and return a dataset...

This general dataset that is returned I wish to cast to a strongly typed
dataset of my choosing.
I have the XML Schema and a generated specialization of the DataSet that I
wan´t to cast to...

Generated by xsd.exe
public class MyStronglyTypedDS : DataSet {
...
}

My app code: (wich causes Invalid Cast Exception...)

MyStronglyTypedDS ds = (MyStronglyTypedDS) obj.GetDataSet("MyStoredProc");
My DAL code:

public DataSet GetDataSet(string sproc) {
....
return ds;
}

I would rely appreciate some feedback!
Thanks

/Oscar

Nov 15 '05 #2

Hi, Oscar Thornell

I have a general all purpose class that can take the name of a stored
procedure and return a dataset...

This general dataset that is returned I wish to cast to a strongly typed
dataset of my choosing.
I have the XML Schema and a generated specialization of the DataSet that I
wan´t to cast to...

Generated by xsd.exe
public class MyStronglyTypedDS : DataSet {
...
}

My app code: (wich causes Invalid Cast Exception...)

MyStronglyTypedDS ds = (MyStronglyTypedDS) obj.GetDataSet("MyStoredProc");


Try

MyStronglyTypedDS ds = new MyStronglyTypedDS();
ds.Merge(obj.GetDataSet("MyStoredProc"));

Hope this helps.

--
Roman S. Golubin
ICQ UIN 63253392
go*****************@arhcity.ru


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: | last post by:
We have an object factory that returns weakly typed datasets (just plain ol' DataSet's). I need to cast it, or transform it, or map it to a strongly typed dataset. There's an old adage I heard...
1
by: Job Lot | last post by:
I am confused how strongly typed dataset is different from un-typed dataset. Is there any good link explaining pros and cons of both? Which one should be used preferably?
2
by: Mark | last post by:
Just wanted to confirm that my understanding of a strongly typed language is correct: 1. .NET is a strongly typed language because each variable / field must be declared a specific type (String,...
7
by: Jeff | last post by:
I want to remote several strongly typed datasets and I don't want to distribute the assemblies. I wish to create interface assemblies for these datasets but I don't know where to start. I've...
20
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the...
1
by: rival | last post by:
Hi. I've a single solution with many projects. I'm using VS2003 and framework 1.1 1. Data project - contains UserData class, inheriting from DataSet, and setting up constants and columns...
1
by: Mike P | last post by:
I have been trying out using strongly typed datasets in VS 2005, and I have to say that I don't like them...they produce loads of auto-generated code, and I would much rather create a single class...
0
by: Ben | last post by:
I'm trying to apply techniques I'd normally use to pull data from SQL/Server to pull XML from SQL/Server, and I'm running into a problem. Here's what I'm doing: 1. I've built a stored...
4
by: Rachana | last post by:
Hi, I have understood Data Sets but what is meant by typed/untyped/ strongly typed datasets. Can any one explain me or suggest any site/ article, to get these concepts (and their ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.