Converting a generic Dataset to a typed dataset

W

William Gower

I have a method called RetrieveAll that returns a Dataset

The object that is calling this method expects to receive a UserDS. I don't
want the RetrieveAll to have to know about the UserDS but just return a
dataset and the calling method will convert it to a specific typed dataset.
How do I do this?

Dim dalc as New UserDALC
Dim user As New UserDS
user = dalc.RetrieveAll()
 
C

Craig Deelsnyder

I have a method called RetrieveAll that returns a Dataset

The object that is calling this method expects to receive a UserDS. I don't
want the RetrieveAll to have to know about the UserDS but just return a
dataset and the calling method will convert it to a specific typed dataset.
How do I do this?

Dim dalc as New UserDALC
Dim user As New UserDS
user = dalc.RetrieveAll()
Does the dalc class have a .Fill method of some sort? To be honest, any
data access layer object I create that 'returns data' has this, as alot
of times a caller may ask to fill an existing structure, instead of
always getting a newly-created return structure. Then you could just
create a typed dataset in the above code and pass to the dalc.Fill(..)
method...

Otherwise you'd pry have to write some utility to copy the data and
structures from one DataSet to the other...
 
B

Brian Baker [MVP]

William said:
I have a method called RetrieveAll that returns a Dataset

The object that is calling this method expects to receive a UserDS. I
don't want the RetrieveAll to have to know about the UserDS but just
return a dataset and the calling method will convert it to a specific
typed dataset. How do I do this?

Here is what I did in a similar situation:

-------------------------------------
Dim ds as Dataset
Dim dsTyped as myTypedDataset

ds = DAL.GetDataSetSP("procname")
ds.Tables(0).TableName("TABLE_NAME_IN_TYPED_DATASET")

dsTyped.Merge(ds)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top