I’m using some TSQL with ‘For XML Auto’. If I run the TSQL in management studio, I get a single row. If I fill the DataTable using the DataAdapter.Fill() command, I get two results. It appears that the results are split in the middle of one of the tags. It is not a huge XML file, in fact its quite small (perhaps 20 lines), so size is likely not the issue. Here’s the SQL.
SELECT Organization.Name,
Organization.Abbreviation,
Organization.WebsiteURL,
Organization.AddressLine1,
Organization.AddressLine2,
Organization.City,
Organization.Province,
Organization.Country,
Organization.PostalCode,
Organization.Phone,
Organization.Email,
Organization.ContactFirstName,
Organization.ContactLastName FROM
StudentLife.MissionWeekOrganization
Organization INNER JOIN
StudentLife.MissionWeekOrganizationAttendee
reg ON
Organization.MissionWeekOrganizationId
= reg.MissionWeekOrganizationId WHERE (reg.AttendingYear = 2010 AND
ReceivedDate IS NOT NULL) ORDER BY
Organization.Name FOR XML AUTO
The results are split right in the middle of an element
… Organization
Name=\”Samaritan’s Purse Canada\”
Abbreviation=\”\” WebsiteURL=\”http
then the second row in the DataTable picks up where it left off. Any ideas?
Thanks for the suggestions guys. I figured it out. The problem isn’t sql server (as I said management studio returns the answer properly in a single row). Adding Type doesn’t help either, (Sql server knew that it was xml right from the start). The problem is that ADO.NET breaks up the results when creating the datatable.
It turns out that I shouldn’t be using the SqlDataReader from Command.ExecuteReader. Instead I should be using the System.Xml.XmlReader from Command.ExecuteXmlReader. Then you do as you suggested, concatenating those results (although it probably would work to just concatenate all the results from all the rows using the DataAdapter.Fill method).
Thus something like this:
Thanks for the help!