[英]retrieve Xml data from database into my page
I am trying to retrieve data into an xml tag from the database using a stored procedure. 我正在尝试使用存储过程从数据库中将数据检索到xml标记中。 I want to create the reponse like standard xml responses.
我想创建类似于标准xml响应的响应。 But instead I am getting a tag named:
<NewDataSet/>
但是相反,我得到了一个名为:
<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, 构造DataAdapter,
SqlDataAdapter adpater=new SqlDataAdapter(comm);
DataSet shop=new DataSet();
adapter.Fill(shop);
XmlDocument cdoc = new XmlDocument();
cdoc.LoadXml(shop.GetXml());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.