473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Converting an untyped datatable into a typed datatable

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
3 6464
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nedu N | last post by:
Hi All, I am facing problem in copying content of table from a untyped dataset into to a table inside the typed dataset. I wanted to copy the data into typed dataset in order to ease the further...
1
by: Somebody_Out_There | last post by:
Hello, I am trying to create a strongly typed datatable/dataset from an untyped dataset or datatable returned from a stored proc. The structure of the table cannot be static since the results...
0
by: Rakesh Rajan | last post by:
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...
2
by: Nedu N | last post by:
Hi Techies, I am facing problem in copying content of table from a untyped dataset into to a table inside the typed dataset. I wanted to copy the data into typed dataset in order to ease the...
7
by: Przemo | last post by:
Hi, I wonder about performerce comparision between these two types of DataSets. Are benefits of typed DataSets enought to beat speed of untyped ones? Or it doesn't matter? What do you think? ...
4
by: Ronald S. Cook | last post by:
I've always used untyped datasets. In a Microsoft course, it walks through creating typed datasets and harps on the benefits. It has you drag all these things around ..wizard, wizard, wizard......
0
by: vrushalik | last post by:
Hi, i want to know pros and cons of both Typed and Untyped dataset in detail. can we customize untyped dataset? What is benefit of Typed dataset? is there significant difference between...
1
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, if i have an untyped datatable of, say, employee id's. Emp ID, Name 14, John 14, John 2, Tom 3, Sally How can I search the datatable to find if EmpID 14 even exists in the table?
1
by: zlf | last post by:
Hello As a known issue, WCF does not allow to transfer typed DataSet. So I have to copy all data from typed DataSet to untyped DataSet(same table names, column names and row data). What is the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.