PC Review


Reply
Thread Tools Rate Thread

Convert a DataTable to a Strongly Typed DataTable.

 
 
Anibal
Guest
Posts: n/a
 
      22nd Jan 2005
Hi,
The following code throws me an Error, i use a method to bring a DataTable
object and i want to asigne it to a Strongly Typed DataTable, but VB doesn't
allow me.
How can i do this right? And if it couldn't be done, then wich would be an
equivalent solution.
Thank you very much.


'FoldersDataTable: Inherits from DataTable.
Dim Data As New FoldersDataTable

'BringDataTable: Retrives a DataTable object
Data = CType(BringDataTable("Select * From Folders"), FoldersDataTable)
'Error: 'InvalidCastExeption'


 
Reply With Quote
 
 
 
 
Ryan Trudelle-Schwarz
Guest
Posts: n/a
 
      22nd Jan 2005
> Hi,
> The following code throws me an Error, i use a method to bring a
> DataTable
> object and i want to asigne it to a Strongly Typed DataTable, but VB
> doesn't
> allow me.
> How can i do this right? And if it couldn't be done, then wich would
> be an
> equivalent solution.
> Thank you very much.
> 'FoldersDataTable: Inherits from DataTable.
> Dim Data As New FoldersDataTable
> 'BringDataTable: Retrives a DataTable object
> Data = CType(BringDataTable("Select * From Folders"),
> FoldersDataTable)
> 'Error: 'InvalidCastExeption'


Right, you are trying to do an upcast essentially, which is never permissable.

You have a few options (OTTOMH):
1) Fill the super data table directly.
2) Copy the data from one to the other.

Obviously 1 will be more performant than 2 but depending on your circumstances
may not be possible.

hth, Ryan

 
Reply With Quote
 
Anibal
Guest
Posts: n/a
 
      22nd Jan 2005
Thanks for your answer,
In my case y can fill the strongly typed DataTable as you've suggested, but
the thing is that right now i am learning this kind of "stuff" (i mean
ADO.NET) while building my application, so i allready have set a proyect for
manipulating data, and i have set al methods in the classes of this proyect
to return DataSet and DataTable objects to use in the buisennes ruels
proyect, so I do want to follow your sugestion of filling directly the
strongly typed DataTable, but how do i arrange the hole design of the tiers.



"Ryan Trudelle-Schwarz" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed)...
>> Hi,
>> The following code throws me an Error, i use a method to bring a
>> DataTable
>> object and i want to asigne it to a Strongly Typed DataTable, but VB
>> doesn't
>> allow me.
>> How can i do this right? And if it couldn't be done, then wich would
>> be an
>> equivalent solution.
>> Thank you very much.
>> 'FoldersDataTable: Inherits from DataTable.
>> Dim Data As New FoldersDataTable
>> 'BringDataTable: Retrives a DataTable object
>> Data = CType(BringDataTable("Select * From Folders"),
>> FoldersDataTable)
>> 'Error: 'InvalidCastExeption'

>
> Right, you are trying to do an upcast essentially, which is never
> permissable.
>
> You have a few options (OTTOMH):
> 1) Fill the super data table directly.
> 2) Copy the data from one to the other.
>
> Obviously 1 will be more performant than 2 but depending on your
> circumstances may not be possible.
>
> hth, Ryan
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd Jan 2005
Anibal,

What is the returntype of
BringDataTable("Select * From Folders")

Cor


 
Reply With Quote
 
Anibal
Guest
Posts: n/a
 
      22nd Jan 2005
The type is a DataTable Object with the data from the SQL statement

"Cor Ligthert" <(E-Mail Removed)> escribió en el mensaje
news:(E-Mail Removed)...
> Anibal,
>
> What is the returntype of
> BringDataTable("Select * From Folders")
>
> Cor
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving/restoring strongly-typed DataTable to/from XML timnels@gmail.com Microsoft Dot NET 0 31st Jan 2007 01:06 PM
Saving/restoring strongly-typed DataTable to/from XML timnels@gmail.com Microsoft C# .NET 0 30th Jan 2007 06:26 PM
BUG: Strongly-typed DataTable GetSchemaSerializable method =?Utf-8?B?SmFzb24=?= Microsoft Dot NET Framework 6 27th Apr 2006 08:00 AM
convert untyped datatable/dataset into strongly typed Somebody_Out_There Microsoft ADO .NET 2 15th May 2004 12:12 AM
convert untyped datatable/dataset into strongly typed Somebody_Out_There Microsoft C# .NET 1 14th May 2004 09:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:43 AM.