[quoted text, click to view] "Don" <doduong12141214@hotmail.com> wrote in message news:OXkLQMQnEHA.3564@tk2msftngp13.phx.gbl...
> When I read my sqlxml results into a reader and deserialize it, I only get
> the first record deserialized into my object.
> If I have five records, they're all in the reader. But how do I get access
> to all of them via an object or objects?
Deserialize() must be called one time for each object
you're deserializing. Here is an example in VB.NET,
- - - SqlXmlDeserialize.vb (excerpt)
' . . .
Dim reader As XmlReader
reader = objCmd.ExecuteXmlReader()
Dim serializer As XmlSerializer
serializer = New XmlSerializer( GetType( employee))
Dim employees As employee()
employees = New employee( 6)
Dim N As Integer
For N = 0 To employees.Length
employees( N) = CType( serializer.Deserialize( reader), employee)
If ( employees( N) Is Nothing ) Then
Console.WriteLine( "#" + CStr( N) + " is Nothing.")
Else
Console.WriteLine( "#" + CStr( N) + " " + employees( N).firstname + " " + employees( N).lastname)
End If
reader.ResetState()
Next N
' . . .
- - -
Observe the special handling of the XmlReader that is
necessary since SQLXML has multiple document elements
in it's results (which makes for a document that isn't
true XML). Unless you want the application to receive
an InvalidOperationException, you must call ResetState()
on the XmlReader after each object has been deserialized.
This call causes the reader's state to forget that it
has read a document's end element, so it can resume
it's processing anew.
Derek Harmon