Dataset to typed dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello
I would like to convert dataset returned by SqlHelper to a typed dataset.
How to do it ? (MyTypedDataSet) SqlHelper.ExecuteDataSet(...) doesn't work :(
It says wrong cast. Any other ideas ?
Jarod
 
Jarod,

It's a little expensive (performance-wise), but you should be able to
call the WriteXml method on the untyped data set (writing to a memory
stream), and then create a new instance of your typed data set and call the
ReadXml method on it, reading from the stream (where you reset the stream
pointer to the beginning).

Hope this helps.
 
It's a little expensive (performance-wise), but you should be able to
call the WriteXml method on the untyped data set (writing to a memory
stream), and then create a new instance of your typed data set and call the
ReadXml method on it, reading from the stream (where you reset the stream
pointer to the beginning).

It doesn't work for me :( MyTypedDataset after ReadXML is empty.
Jarod
 
Nicholas Paldino said:
Jarod,

It's a little expensive (performance-wise), but you should be able to
call the WriteXml method on the untyped data set (writing to a memory
stream), and then create a new instance of your typed data set and call the
ReadXml method on it, reading from the stream (where you reset the stream
pointer to the beginning).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jarod said:
hello
I would like to convert dataset returned by SqlHelper to a typed dataset.
How to do it ? (MyTypedDataSet) SqlHelper.ExecuteDataSet(...) doesn't work
:(
It says wrong cast. Any other ideas ?
Jarod
 
It's a little expensive (performance-wise), but you should be able to
call the WriteXml method on the untyped data set (writing to a memory
stream), and then create a new instance of your typed data set and call the
ReadXml method on it, reading from the stream (where you reset the stream
pointer to the beginning).

It doesn't work for me ;( The new typed dataset after ReadXml is empty :(
Jarod
 
It's a little expensive (performance-wise), but you should be able to
call the WriteXml method on the untyped data set (writing to a memory
stream), and then create a new instance of your typed data set and call the
ReadXml method on it, reading from the stream (where you reset the stream
pointer to the beginning).

Almost good but... doesn't work. But I make it work ;)))
So first we need to ReadXmlSchema(pathToFile)
then we need to change the table name in untyped dataset
ds.Tables[0].TableName = "OurTableName"

With this two corrects it really works :)
Jarod
 
Jarod said:
hello
I would like to convert dataset returned by SqlHelper to a typed dataset.
How to do it ? (MyTypedDataSet) SqlHelper.ExecuteDataSet(...) doesn't work
:(
It says wrong cast. Any other ideas ?
Jarod

This is how I do it:

// load the generic data from the data layer into a strongly typed dataset
dsTyped.Load(dsUntyped.Tables[0].CreateDataReader(),
LoadOption.OverwriteChanges, dsTyped.mytablename);

HTH,

Mike Rodriguez
 

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

Back
Top