Serialization
Create an empty instance of your object
Dim Obj as New MYOBJECT
Dim cn As New SqlConnection(ConnectionString.Text_)
Dim cmd As New SqlCommand
Dim Trans As SqlTransaction
With cmd
.Connection = cn
.Transaction = Trans
.CommandType = CommandType.StoredProcedure
.CommandText = "somestoredprocedure"
Dim xMLSerialiser_ As New System.Xml.Serialization.XmlSerializer(Obj.GetType)
Dim sWriter As New System.IO.StringWriter
xMLSerialiser_.Serialize(sWriter, Obj)
'add xml to database
.Parameters.AddWithValue("@persistxml", sWriter.ToString)
End With
cmd.ExecuteNonQuery()
Trans.Commit()
DeSerialization
Dim Obj as New MYOBJECT
cn.Open()
With cmd
.Connection = cn
.CommandType = CommandType.Text
.CommandText = "select persistxml from SomeTable where wf_id = @id AND wf_instanceguid=@guid"
.Parameters.AddWithValue("@id", Id_)
.Parameters.AddWithValue("@guid", GUID_)
End With
‘FILL THE DATASET
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
If Not IsDBNull(ds.Tables(0).Rows(0).Item("persistxml")) Then
Dim stringReader_ As New System.IO.StringReader(ds.Tables(0).Rows(0).Item("persistxml"))
Dim xSerialiser_ As New System.Xml.Serialization.XmlSerializer(Obj.GetType)
Obj= xSerialiser_.Deserialize(stringReader_)
End If
End If
Comments
Post a Comment