473,699 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.Dat aTable, add it to a System.Data.Dat aSet (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.
Nov 6 '06 #1
3 1842
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.F ormatters.Binar y

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(ByV al Argdata() As Byte) As Object
Dim m As New MemoryStream(Ar gdata)
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." wrote:
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.Dat aTable, add it to a System.Data.Dat aSet (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.
Nov 7 '06 #2

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 [MCP]" wrote:
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.F ormatters.Binar y

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(ByV al Argdata() As Byte) As Object
Dim m As New MemoryStream(Ar gdata)
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." wrote:
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.Dat aTable, add it to a System.Data.Dat aSet (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.
Nov 7 '06 #3
Michel Posseth [MCP] wrote:
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.
Nov 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
2974
by: Frank Buss | last post by:
I've setup a challenge, mainly for C++, Java and Lisp, but every other language is welcome: http://www.frank-buss.de/challenge/index.html There is nothing to win, but I hope there will be some interesting solutions at the end, so the win are the results :-) -- Frank Buß, fb@frank-buss.de
8
1705
by: Frank Buss | last post by:
A new challenge: http://www.frank-buss.de/marsrescue/index.html Have fun! Now you can win real prices. -- Frank Buß, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de
67
2929
by: Scott M. | last post by:
Can anyone give me any ideas on why VS.NET 2003 running on XP Pro. (P4's with 1GB RAM) would take over 3 minutes to simply create a new ASP.NET Web Application on http://localhost? It seems that the IIS directory gets created right away, but it is not configured as an application directory until several minutes go by. Thanks, Scott M.
0
8706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9055
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8945
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8902
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7787
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4641
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.