473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to use this class? A little bit confused. Thank You.

Hello,

I followed some examples in internet and in MSDN web site to create a
serializable class.

Basically, I need to serialize a class to binary so I can save it in
an SQL 2005 table using a column of type VARBINARY (SQL 2005). And
also deserialize and return the class.

My problem is how to use the class. Of course I know how to create an
instance of this class.

I also know that I should run the method Serialize so I can get a
binary instance of it and Deserialize, providing a Byte() taked from
the database, to get a class.

I think this far so good.

My problem is when creating the class using NEW one of the
constructors have:

ByVal siRows As SerializationInfo, ByVal scRows As StreamingContext

What should I provide in this?

I created this code based on various examples so I am not sure if I
made some mistakes.

Could someone, please, tell me if I am doing everything right?

Anyway, here is my entire code:

1 <Serializable()_
2 Public Class Rows
3 Implements ISerializable
4
5 Private _Rows As New Generic.List(Of Row)
6 Public Property Rows() As Generic.List(Of Row)
7 Get
8 Return _Rows
9 End Get
10 Set(ByVal value As Generic.List(Of Row))
11 _Rows = value
12 End Set
13 End Property ' Rows
14
15 Public Sub New()
16 End Sub ' New
17
18 Public Sub New(ByVal siRows As SerializationInfo, ByVal scRows
As StreamingContext)
19 Me.Rows = siRows.GetValue("Rows", GetType(Row))
20 End Sub ' New
21
22 Public Sub GetObjectData(ByVal siRows As SerializationInfo,
ByVal scRows As StreamingContext) Implements
ISerializable.GetObjectData
23 siRows.AddValue("Rows", Me.Rows)
24 End Sub ' GetObjectData
25
26 Public Function Serialize() As Byte()
27 Dim bRows() As Byte = New Byte() {}
28 Dim sRows As Stream = Stream.Null
29
30 Try
31 sRows.Read(bRows, 0, Integer.MaxValue)
32 Dim bfRows As New BinaryFormatter
33 bfRows.Serialize(sRows, Me)
34 Finally
35 sRows.Close()
36 End Try
37 Return bRows
38
39 End Function ' Serialize
40
41 Public Shared Function Deserialize(ByVal data As Byte()) As
Rows
42
43 Dim sRows As Stream = Stream.Null
44 Try
45 sRows.Write(data, 0, data.Length)
46 Dim bfRows As New BinaryFormatter
47 Return CType(bfRows.Deserialize(sRows), Rows)
48 Finally
49 sRows.Close()
50 End Try
51
52 End Function ' Deserialize
53
54 End Class ' Rows
Thanks,

Miguel

Mar 11 '07 #1
0 1139

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

Similar topics

5
by: martin | last post by:
Hi, The trace class seems to me to be very usefull however there are a few features of it that have to confused. I am using visual studio 2003. the IDE will not let me write ...
5
by: Jeff Cobelli | last post by:
I am trying to include two classes as members of another class in a webservice. The definitions look basically like this: Public Class clsLender Public ID As String Public Name As String End...
5
by: Diffident | last post by:
Hello All, I am designing a class based on singleton pattern. Inside this class I have multiple instance methods. My question is since there will be only one instance of this class at any...
16
by: digitalorganics | last post by:
What's the difference between initializing class variables within the class definition directly versus initializing them within the class's __init__ method? Is there a reason, perhaps in certain...
3
by: Tom Machado | last post by:
Hello, I am working on a project and have become a little confused on how to call methods from another class. Before I explain, here is an example: class 0 { main() {
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
6
by: toton | last post by:
Hi, If I have a singleton class based on dynamic initialization (with new ) , is it considered a memory leak? Anything in C++ standard says about it ? And little off - topic question , If the...
1
by: johnsonlau | last post by:
When a class derives from a class, You can use a pointer to the parent class to delete the instance of child only when a virtual destructor declared in the parent. class Parent { virtual...
3
by: shapper | last post by:
Hello, I have a class as follows: public class UserPaper { public MembershipUser user { get; set; } public string Password { get; set; } public UserLeaf(MembershipUser newUser) {...
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
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...
1
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...
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.