locked
Serialize / DeSerialize RRS feed

  • Question

  • User-1326749442 posted

    I am trying to use the Serialize / DeSerialize methods in ASP.NET (VB) 2005. I have been able to serialize a custom class (SQLListing.SavedSQL) then saved this output to a field within a database. The problem is DeSerialize the information. The code extracts the information from the database (stored as a byte).

    Within "Private Sub DeSerialise" the variable"Temp" contains information but when doing "MemStream.Write(Temp, 0, Temp.Length)" there is nothing in "MemStream"

    Private Sub DeSerialise()

    Dim MySerializer As XmlSerializer = New XmlSerializer(GetType(SQLListing.SavedSQL))

    Dim dt As New ds.SQLListingDataTable

    Dim SQLListing As New SQLListing.SavedSQL

    Dim TAGetInformation As New dsTableAdapters.SQLListingTableAdapter

    TAGetInformation.Fill(dt)

    For Each row As DataRow In dt.Rows

    Dim MemStream As New MemoryStream

    Dim Temp(8000) As Byte

    Temp = CType((row.Item(2)), Byte())

    MemStream.Write(Temp, 0, Temp.Length)

    SQLListing = MySerializer.Deserialize(MemStream)

    Next row

    End Sub

    Private Sub AddRemoveField(ByVal SourceList As ListBox, ByVal DestList As ListBox)

    If SourceList.SelectedIndex > -1 Then

    Dim SQLRecord As New SQLListing.SavedSQL

    Dim MemStream As New MemoryStream

    With SQLRecord

    .FilterField = ""

    .FilterOp = ""

    .FilterValue = ""

    .SQLFieldPosition = DestList.Items.Count

    .SQLFieldText = SourceList.SelectedItem.Text

    .SQLFieldValue = SourceList.SelectedItem.Value

    .SQLType = "GROUP"

    End With

    Dim MySerializer As XmlSerializer = New XmlSerializer(GetType(SQLListing.SavedSQL))

    MySerializer.Serialize(MemStream, SQLRecord)

    Serialise(MemStream)

    DestList.Items.Add(SourceList.SelectedItem)

    SourceList.Items.Remove(SourceList.SelectedItem)

    DeSerialise()

    End If

    SourceList.SelectedIndex = -1

    DestList.SelectedIndex = -1

    End Sub

    Namespace SQLListing

    <XmlRoot(ElementName:="SavedSQL")> _

    Public Class SavedSQL

    Private _SQLType As String

    Private _SQLFieldValue As String

    Private _SQLFieldText As String

    Private _SQLFieldPosition As String

    Private _FilterField As String

    Private _FilterOp As String

    Private _FilterValue As String

    <XmlElement(elementName:="SQLType")> _

    Public Property SQLType() As String

    Get

    Return _SQLType

    End Get

    Set(ByVal value As String)

    _SQLType = value

    End Set

    End Property

    <XmlElement(elementName:="SQLFieldValue")> _

    Public Property SQLFieldValue()

    Get

    Return _SQLFieldValue

    End Get

    Set(ByVal value)

    _SQLFieldValue = value

    End Set

    End Property

    <XmlElement(elementName:="SQLFieldText")> _

    Public Property SQLFieldText()

    Get

    Return _SQLFieldText

    End Get

    Set(ByVal value)

    _SQLFieldText = value

    End Set

    End Property

    <XmlElement(elementName:="SQLFieldPosition")> _

    Public Property SQLFieldPosition()

    Get

    Return _SQLFieldPosition

    End Get

    Set(ByVal value)

    _SQLFieldPosition = value

    End Set

    End Property

    <XmlElement(elementName:="FilterField")> _

    Public Property FilterField() As String

    Get

    Return _FilterField

    End Get

    Set(ByVal value As String)

    _FilterField = value

    End Set

    End Property

    <XmlElement(elementName:="FilterOp")> _

    Public Property FilterOp() As String

    Get

    Return _FilterOp

    End Get

    Set(ByVal value As String)

    _FilterOp = value

    End Set

    End Property

    <XmlElement(elementName:="FilterValue")> _

    Public Property FilterValue() As String

    Get

    Return _FilterValue

    End Get

    Set(ByVal value As String)

    _FilterValue = value

    End Set

    End Property

    End Class

    End Namespace

    Monday, February 26, 2007 10:57 AM

All replies