Xmlreader steals records...

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

I have a problem:
command returns X records based on some select. I want to build xmldocument
from xmlreader so I do this..., however instead of X records I recieve XML
with X-1 records... WHY????
here is the code:
reader = command.ExecuteXmlReader()


While reader.Read()


sTmpVal = sTmpVal & reader.ReadOuterXml

End While
 
Hi Tamir ,

These code works for me.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim myCommand As SqlCommand = New SqlCommand("select * from
employees FOR XML AUTO, XMLDATA", SqlConnection1)
SqlConnection1.Open()

Dim myXmlReader As System.Xml.XmlReader =
myCommand.ExecuteXmlReader()
Dim i As Integer
i = 0
myXmlReader.Read()

Do While myXmlReader.ReadState <> Xml.ReadState.EndOfFile
i = i + 1
Debug.WriteLine(i.ToString() + ": " +
myXmlReader.ReadOuterXml())
Loop
' Always close the XmlReader when finished.
myXmlReader.Close()

End Sub

For detailed information, please take a look at the link below.
HOW TO: Use the ExecuteXmlReader Method of the SqlCommand Class in Visual
Basic .NET
http://support.microsoft.com/?id=316016


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

As the document said,
XmlReader.ReadOuterXml Method
If the reader is positioned on a leaf node, calling ReadOuterXml is
equivalent to calling Read.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
XmlReader.Read Method
When overridden in a derived class, reads the next node from the stream.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemxmlxmlreaderclassreadouterxmltopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemxmlxmlreaderclassreadtopic.asp

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top