Convering typed and un-typed datasets to each other

  • Thread starter Thread starter A.M-SG
  • Start date Start date
A

A.M-SG

Hi,



What is the best way to convert a typed dataset to un-typed one? And also
what would the best way to convert un-typed dataset to typed one with
similar structure?



Is there any online resources give me a guidelines and best practices?



Thank you,

Alan
 
Alan,

Any typed dataset is a untyped dataset, a untyped dataset is not a typed
dataset.
A typed dataset inherits from a non typed one.

So this goes,
ds.tables("mytable") can be the same as ds.mytable if you have a typed
dataset.

However never if you don't have that, than you have to build that class
yourself or use the designer or whatever other tool.

I hope this helps,

Cor
 
Strongly typed means just that unfortunately, and they can't be converted.
You can copy the values to and from each other. However, depending on what
you want to do, you can turn off the constraints which may effecitively turn
your typed dataset into an untyped one behavior wise. However, having two
copies of the same data isn't efficient so I don't really know of a 'best
practice' in this respect. Can you tell me a little more about the end goal
here and perhaps I can give you some better guidance.

Thanks,

Bill
 
Hi,

This might work:
Use the WriteXml method of the untyped dataset to get the xml
representation, and then use the ReadXml method of the typed dataset to read
into it.

But of course, the structure should be the same.
 
Hi Bill,

At runtime I have to convert typed datasets to untyped then send them to a
soap client and then receive the dataset and convert it to typed one.

To convert a typed dataset to untyped one, I simply use implicit casting:
untypedDS=typedDS

To convert a untyped dataset to typed one I use merge:
typedDS.Merge(untypedDS, false, MissingSchemaAction.Error)// That assures
that schemas match otherwise and error pops up

I was wondering that is the the best approach or not.

Thank you,
Alan
 
Hi Alan,

As far as I know, the only workaround to convert an untyped DataSet to a
typed one, is to use merge or xml to transfer data. I think your approach
is fine.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Alan:

Merge actually merges one dataset into another - I thought you were
referring to casting one from one type to another. Sorry for the confusion
 
Back
Top