1
我想從數據庫檢索數據到一個XML標記使用存儲過程。我想創建像標準XML響應一樣的響應。而是我得到一個名爲標籤:<NewDataSet/>
從數據庫檢索Xml數據到我的頁面
這是我檢索數據的代碼:
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());
可以做些什麼?謝謝。
DataSet shop = new DataSet();
XmlDocument cdoc = new XmlDocument();
這是我的存儲過程:
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 @[email protected]
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
什麼是CDOC和店?你在哪裏執行命令?我懷疑最後一行與sql命令無關,你正在查看一些現有值而不是命令的結果。如果您想檢索結果,您必須執行comm.ExecuteScalar或comm.ExecuteReader –
您可以共享您的存儲過程嗎? – Asif
嘿!謝謝!我編輯了它..我正在嘗試你的建議..再次感謝 –