Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > my.settings : A 'DataTable' field won't get serialized in an application setting.
 

my.settings : A 'DataTable' field won't get serialized in an application setting.

Hey guys,

I have a setting of a custom type, which has a 'DataTable' member to store some info. The member doesn't get serialized into the user.config file, but a string type member gets serialized ok. On the other hand, a 'DataTable' type setting serializes with no trouble.
Mr Robot  Thursday, March 13, 2008 5:57 AM
Hi,

In this scenario datatable doesn't support this serialization functionality. We can customize the class type to serialize the string array to replace datatable as a workround. Hope this helps.

Imports System.Runtime.Serialization

<Serializable()> Public Class Class1

Implements ISerializable

Public datarow() As String

Public str As String

Public num As String

Public Sub New()

str = "test1"

num = 4

ReDim datarow(4)

For i As Integer = 0 To 4

datarow(i) = i.ToString & vbTab & "name " & i.ToString

Next

End Sub

Public Overridable Sub getobjecdata(ByVal info As SerializationInfo, ByVal context As StreamingContext) Implements ISerializable.GetObjectData

info.AddValue("string", str)

num = datarow.Length

info.AddValue("number", num)

For i As Integer = 0 To num - 1

info.AddValue("row" & i.ToString, datarow(i))

Next

End Sub

Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)

str = info.GetString("string")

num = info.GetInt32("number")

ReDim datarow(num - 1)

For i As Integer = 0 To num - 1

datarow(i) = info.GetString("row" & i.ToString)

Next

End Sub

End Class



Best regards,
Riquel
Riquel_Dong  Wednesday, March 19, 2008 3:38 AM
Hi,

In this scenario datatable doesn't support this serialization functionality. We can customize the class type to serialize the string array to replace datatable as a workround. Hope this helps.

Imports System.Runtime.Serialization

<Serializable()> Public Class Class1

Implements ISerializable

Public datarow() As String

Public str As String

Public num As String

Public Sub New()

str = "test1"

num = 4

ReDim datarow(4)

For i As Integer = 0 To 4

datarow(i) = i.ToString & vbTab & "name " & i.ToString

Next

End Sub

Public Overridable Sub getobjecdata(ByVal info As SerializationInfo, ByVal context As StreamingContext) Implements ISerializable.GetObjectData

info.AddValue("string", str)

num = datarow.Length

info.AddValue("number", num)

For i As Integer = 0 To num - 1

info.AddValue("row" & i.ToString, datarow(i))

Next

End Sub

Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)

str = info.GetString("string")

num = info.GetInt32("number")

ReDim datarow(num - 1)

For i As Integer = 0 To num - 1

datarow(i) = info.GetString("row" & i.ToString)

Next

End Sub

End Class



Best regards,
Riquel
Riquel_Dong  Wednesday, March 19, 2008 3:38 AM

You can use google to search for other answers

Custom Search

More Threads

• For ... Next Loop in number changing controls
• Read a webpage Metadata
• Network Question
• Invoker method problem
• Displaying array in TextBox
• Using Bit Mask and SQL Server Binary Data Type
• PictureBox i slow...
• How
• Can't access a static property in VB while fine in C#
• Server Connection