473,757 Members | 10,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 MyStronglyTyped DS : DataSet {
....
}

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

MyStronglyTyped DS ds = (MyStronglyType dDS) obj.GetDataSet( "MyStoredProc") ;
My DAL code:

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

I would rely appreciate some feedback!
Thanks

/Oscar
Nov 15 '05 #1
2 4263
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.co m

"Oscar Thornell" <os***@cyberode .se> wrote in message
news:up******** ******@TK2MSFTN GP11.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 MyStronglyTyped DS : DataSet {
...
}

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

MyStronglyTyped DS ds = (MyStronglyType dDS) obj.GetDataSet( "MyStoredProc") ;
My DAL code:

public DataSet GetDataSet(stri ng 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 MyStronglyTyped DS : DataSet {
...
}

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

MyStronglyTyped DS ds = (MyStronglyType dDS) obj.GetDataSet( "MyStoredProc") ;


Try

MyStronglyTyped DS ds = new MyStronglyTyped DS();
ds.Merge(obj.Ge tDataSet("MySto redProc"));

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
2110
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 from a Microsoft developer a long time ago: If it's taking more than 10 lines of code, then you are doing it wrong. Is there an *easy* way to do this in a *generic* way? I have been experimenting with serveral techniques and
1
6089
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
2380
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, Int, Float, etc...) 2. VB 6 and VBScript were not strongly typed because both allowed you to ... dim blah .... which creates a variant.
7
7041
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 tried to use soapsuds, but this did not work correctly. I tried to use NMatrix XofG, but this seems very complicated. All I need is something that will convert a class file into an interface. Is there anything already built that will do this? ...
20
5983
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 arraylist then I have to handle this with a sort method that uses comparer. I can reference the properties of the Arraylist directly such as dim mylist as new FrameList mylist.Add(new FrameStructure) mylist(0).first = "blabla..." mylist(0).second...
1
2928
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 like those found in the Duwamish 7 sample 2. WebServices project - wraps up business logic 3. C# winforms consumer connecting to the WebServices. This project has the data project as a reference.
1
1297
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 to deal with all my data access and write it all manually. Is there anything good to say about about strongly typed datasets, or should I just not bother using them? *** Sent via Developersdex http://www.developersdex.com ***
0
1054
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 procedure that pulls my data, and renders it into proper XML. I'm using 'FOR XML AUTO, ELEMENTS', but I'll bet the issues would occur with EXPLICIT also. 2. Using VS2005, I've added a DataSet item, and have dragged the sProc into the dataset so I can...
4
3112
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 comparisions) cleared? Thanks, Rachana
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.