I have a varchar(max) field in SQL 2008 Dataset_XML. My strongly typed business object is mapped to that column, and returns
<dsPolicies xmlns="http://tempuri.org/dsPolicies.xsd" />
for a null. ( this is because I am adding this field to a current app an have to allow nulls, but I could script this as a value for all null values and then not allow nulls if that would help)
dsPolicies is dropped on the form and the instance is names dsPolicies1.
The dataset is typed with 8 tables. and the XSD file seems to be working as I am using bindingsources for each table and the datagridviews are showing the right columns.
In the parentform_loading event of the business object on the Policies form I am trying to deserialize the XML stored in Me.PoliciesBO1.Dataset_XML ( which has the default value shown above) using this code :
Private Sub PoliciesBO1_ParentFormLoading() Handles PoliciesBO1.ParentFormLoading
Me.PoliciesBO1.fillall()
If Me.PoliciesBO1.Count > 0 Then
Me.DsPolicies1 = _ CType(InsurtecPW.Base.Utility.SmartDeSerialize(Me.PoliciesBO1.Dataset_XML), InsurtecPW.dsPolicies)
End If
End Sub
and this is the deserialize routine :
Public Shared Function SmartDeSerialize(ByVal serialized As String) As DataSet
Dim __ds As DataSet = New DataSet
Dim nt As NameTable = New NameTable
Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(nt)
Dim context As XmlParserContext = New XmlParserContext(Nothing, nsmgr, Nothing, XmlSpace.None)
Dim tr As XmlTextReader = New XmlTextReader(serialized, XmlNodeType.Document, context)
Try
__ds.ReadXml(tr)
Return __ds
Finally
If Not (tr Is Nothing) Then
tr.Close()
tr = Nothing
End If
context = Nothing
nsmgr = Nothing
nt = Nothing
End Try
End Function
As you see, this returns a dataset, but I don't seem to be able to cast the return value as the dsPolicies that I need.
Unable to cast object of type 'System.Data.DataSet' to type 'InsurtecPW.dsPolicies'.
I have also tried a directcast of the returned dataset and got the same result.
This approach seemed to work find when I was using an untyped dataset.
I'd appreciate any thoughts on this. I'm pretty clueless about possible differences between the dataset class and a typed dataset or if my problem is the value I am returning if the column is empty.
I am open to any approach (including serializing to a byte array) which will allow me to write and entire dataset to a sql column and bring it back.
Suggestions very much appreciated.
TIA
Charles Hankey
Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy
Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.
-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin
Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.