Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / November 2006

Tip: Looking for answers? Try searching our database.

Challenge?  [De-]Serialise a class derived from DataTable.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phill W. - 06 Nov 2006 16:33 GMT
OK, I've asked nicely before; now I'm going to throw down the gauntlet
to anyone brave enough to take it up.

In VB'2005, can anyone write me a class that inherits from
System.Data.DataTable, add it to a System.Data.DataSet (a /normal/ one,
/not/ a subclass), serialise the whole lot to, say, a file and then
deserialise the whole shooting match back into the classes they started
with?  (All my attempts seem to lose all the Type information on the
DataTable-derived calss in the serialisation process).

I've tried to do this repeatedly (in VB'2003 and '2005) with no success.

I'm not looking for the page and pages of XML Schema "stuff" created by
a Strongly-typed Dataset (although I'm afraid that's where I'll wind
up).  I'm /trying/ to get a Strongly-Typed DataTable that can exist
within any old DataSet.

Is this possible in VB'2005?  (It wasn't in '2003).

TIA,
   Phill  W.
Michel Posseth [MCP] - 07 Nov 2006 07:56 GMT
Have you tried binary serialization ?

i use this to serialize anny .Net object to a sql server database (  Classes
, structures  ) when i deserialize them i get them  back in the original  
state .


<code >
Imports System.Runtime.Serialization.Formatters.Binary

add this attribute to the serializable class
<Serializable()> _

--- methods

''' <summary>
   ''' maakt van een byte array een object  
   ''' </summary>
   ''' <param name="Argdata">de ruwe binaire data </param>
   ''' <returns></returns>
   Private Function DeSerialize(ByVal Argdata() As Byte) As Object
       Dim m As New MemoryStream(Argdata)
       Dim b As New BinaryFormatter()
       m.Seek(0, 0) 'start
       Return b.Deserialize(m)
   End Function
   ''' <summary>
   ''' Maakt van een Object (foo) een byte array .
   ''' </summary>
   ''' <param name="Argdata">argdata als foo object</param>
   ''' <returns></returns>
   Private Function Serialize(ByVal Argdata As Object) As Byte()
       Dim b As New BinaryFormatter
       Dim m As New MemoryStream
       b.Serialize(m, Argdata)
       m.Seek(0, 0) 'start
       Return m.ToArray
   End Function

</code >

With these methods i could store  ( until sofar )  every .Net object in SQL
server
(  you could also write the binary data   out to a file and read it back
from a file )

I hope this helps you in the right direction

regards

Michel Posseth [MCP]

> OK, I've asked nicely before; now I'm going to throw down the gauntlet
> to anyone brave enough to take it up.
[quoted text clipped - 17 lines]
> TIA,
>     Phill  W.
Michel Posseth [MCP] - 07 Nov 2006 10:49 GMT
When i rethink this ....

i believe this is never going to work with a standard dataset

as the deserialize method needs a type that is the same as the serialized
object

and a standard  dataset type is not the same as a dataset with a custom
table , so the  deserialization will probably crash on the custom table ...

so i guess you can only do this with standard datatypes or a custom wrapper

I for instance write my own custom datat types to a database
however when i retrieve the values for serialization i can use this custom
type as my serialization template

in the case of a dataset that holds a custom datatable you miss the mask for
this custom datatable for correct deserialization .

Hmmm  , :-|  ,,, Interesting .......

i guess that if you used a class as wrapper , with an object array to hold
the custom datatables you would not have anny problem,  this way you should
first cast the wrapper wich would give you the class with datatables as
objects , now you could cast these objects to your custom tables  

Well i guess i picked up the gloves , but need to throw the towel in the
ring for the original task  :-)

regards

Michel  



> Have you tried binary serialization ?
>
[quoted text clipped - 69 lines]
> > TIA,
> >     Phill  W.
Phill W. - 07 Nov 2006 15:40 GMT
> When i rethink this ....
> i believe this is never going to work with a standard dataset as the
[quoted text clipped - 4 lines]
>
> so i guess you can only do this with standard datatypes or a custom wrapper
. . .
> in the case of a dataset that holds a custom datatable you miss the mask for
> this custom datatable for correct deserialization .

And therein lies my problem...   :-(

> Hmmm  , :-|  ,,, Interesting .......

"Veeerry interesting" (says the german chap in the helmet hiding behind
the potted plant) "but Stupid"...  Why should a class derived from
DataTable [de-]serialise any differently to any other class?

> Well i guess i picked up the gloves , but need to throw the towel in the
> ring for the original task  :-)

Ah well; at least I have a nice new towel in exchange for my old
gloves...  :-)

Thanks anyway.
   Phill  W.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.