By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

Converting an untyped datatable into a typed datatable

P: n/a
Hi,

I have a method, which opens a connection, creates an untyped datable, fills it and returns it back.

I have defined a typed datatable in my application as well. For some reasons, I have to call the above mentioned method to get data. Unfortunately, as it returns an untyped datatable, I can't assign my typed datatable variable this value (a base type can't be converted into a sub type automatically).

Without resorting to looping thru the rows and assigning it manually, are there any other procedures so that i could assign the untyped data into my typed datatable? I believe reflection might help.

Thanks in advance!
--
Rakesh Rajan
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rakesh,

You should be able to save the XML to a stream using the WriteXml
method. Then, create a new instance of the typed data set, and call the
ReadXml method on it, passing the stream that you saved the XML to.

You might want to consider using a temporary file for this, if the cost
of holding all the XML in memory is too high.

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

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
Hi,

I have a method, which opens a connection, creates an untyped datable, fills it and returns it back.
I have defined a typed datatable in my application as well. For some reasons, I have to call the above mentioned method to get data.
Unfortunately, as it returns an untyped datatable, I can't assign my typed
datatable variable this value (a base type can't be converted into a sub
type automatically).
Without resorting to looping thru the rows and assigning it manually, are there any other procedures so that i could assign the untyped data into my
typed datatable? I believe reflection might help.
Thanks in advance!
--
Rakesh Rajan

Nov 16 '05 #2

P: n/a
Hi Nicholas,

Thanks a lot!

But aren't there any more 'graceful' methods?
--
Rakesh Rajan
"Nicholas Paldino [.NET/C# MVP]" wrote:
Rakesh,

You should be able to save the XML to a stream using the WriteXml
method. Then, create a new instance of the typed data set, and call the
ReadXml method on it, passing the stream that you saved the XML to.

You might want to consider using a temporary file for this, if the cost
of holding all the XML in memory is too high.

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

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
Hi,

I have a method, which opens a connection, creates an untyped datable,

fills it and returns it back.

I have defined a typed datatable in my application as well. For some

reasons, I have to call the above mentioned method to get data.
Unfortunately, as it returns an untyped datatable, I can't assign my typed
datatable variable this value (a base type can't be converted into a sub
type automatically).

Without resorting to looping thru the rows and assigning it manually, are

there any other procedures so that i could assign the untyped data into my
typed datatable? I believe reflection might help.

Thanks in advance!
--
Rakesh Rajan


Nov 16 '05 #3

P: n/a
Rakesh,

That IS the graceful method. Since strongly typed data sets derive from
DataSet, and the strong-typedness (if that is a word) comes from added
methods and properties to that data set, it would make sense to use the
methods that already exist on the DataSet to populate it. You could create
a constructor on your strongly typed data set that takes a stream, or a
DataSet and performs this operation for you. That's about as easy as it
could get.

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

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
Hi Nicholas,

Thanks a lot!

But aren't there any more 'graceful' methods?
--
Rakesh Rajan
"Nicholas Paldino [.NET/C# MVP]" wrote:
Rakesh,

You should be able to save the XML to a stream using the WriteXml
method. Then, create a new instance of the typed data set, and call the
ReadXml method on it, passing the stream that you saved the XML to.

You might want to consider using a temporary file for this, if the cost of holding all the XML in memory is too high.

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

"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
Hi,

I have a method, which opens a connection, creates an untyped datable,

fills it and returns it back.

I have defined a typed datatable in my application as well. For some

reasons, I have to call the above mentioned method to get data.
Unfortunately, as it returns an untyped datatable, I can't assign my typed datatable variable this value (a base type can't be converted into a sub
type automatically).

Without resorting to looping thru the rows and assigning it manually,
are there any other procedures so that i could assign the untyped data into my typed datatable? I believe reflection might help.

Thanks in advance!
--
Rakesh Rajan


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.