I am trying to retrieve data into an xml tag from the database using a stored procedure. I want to create the reponse like standard xml responses. But instead I am getting a tag named: <NewDataSet/>
This is my code for retrieving data:
comm = new SqlCommand("[sp_get_business_locations]", conn);
comm.CommandType = System.Data.CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@Latitude", Latitude);
comm.Parameters.AddWithValue("@Longitude", Longitude);
comm.ExecuteNonQuery();
cdoc.LoadXml(shop.GetXml());
What can be done? Thanks.
DataSet shop = new DataSet();
XmlDocument cdoc = new XmlDocument();
This is my stored procedure:
SElECT @TotalRows=COUNT(*) FROM HeritageList
INNER JOIN Reviews loc WITH (NOLOCK) ON HeritageList.HeritageId = loc.HeritageId
WHERE ([dbo].[DistanceBetween] (@Latitude,@Longitude,Latitude,Longitude)) * @meters <= @Radius
IF(@TotalRows>0)
BEGIN
DECLARE @Partialxml XML
DECLARE @Totalxml XML
declare @Appendxml VARCHAR(100)
SET @Appendxml = '<HeritageList></HeritageList>';
set @Totalxml=@Appendxml
SET @Partialxml = (SELECT HeritageList.HeritageId,
Latitude as "Location/Latitude",
Longitude as "Location/Longitude",
Country as "Location/Country",
[State] as "Location/State",
City as "Location/City",
Postcode as "Location/Postcode",
[Address] as "Location/Address",
(Cast(Round((( [dbo].[DistanceBetween]
(@Latitude,@Longitude,Latitude,Longitude)) * @meters),2,1) as decimal(18,2))) as Distance
FROM dbo.HeritageList INNER JOIN Reviews loc WITH (NOLOCK) ON HeritageList.HeritageId = loc.HeritageId
WHERE ([dbo].[DistanceBetween] (@Latitude,@Longitude,Latitude,Longitude)) * @meters <= @Radius
FOR XML PATH('Business'), ELEMENTS XSINIL)
SET @Totalxml.modify('insert sql:variable("@Partialxml") as last into (/HeritageList)[1] ' )
SELECT @Totalxml
END
END
Construct the DataAdapter,
SqlDataAdapter adpater=new SqlDataAdapter(comm);
DataSet shop=new DataSet();
adapter.Fill(shop);
XmlDocument cdoc = new XmlDocument();
cdoc.LoadXml(shop.GetXml());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.