Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Casting strong type DS as dataset
Message
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01438526
Message ID:
01438586
Views:
52
This is as good a place as any to compliment you (again) on the high quality of your .NET posts. You are not only knowledgeable but helpful. I hope you are not overlooked again when the next round of MVPs is announced.


>Does it work it you use a new instance of the strongly-typed dataset for the .ReadXml(tr) ?
>Of course if so you'd need to change the SmartDeSerialize method to accept an existing instance as a ref parameter (forget the equivalent in VB)
>Regards,
>Viv
>
>>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
>>        ' needed to create an XML TextReader 
>>        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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform