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

P

Phill W.

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.
 
G

Guest

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]
 
G

Guest

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







Michel Posseth said:
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]


Phill W. said:
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.
 
P

Phill W.

Michel said:
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 .. . .
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.
 

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

Top