1

我正在尝试使用存储过程将数据从数据库中检索到 xml 标记中。我想创建像标准 xml 响应一样的响应。但相反,我得到了一个名为:<NewDataSet/>

这是我检索数据的代码:

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 @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 
4

1 回答 1

0

构造数据适配器,

SqlDataAdapter adpater=new SqlDataAdapter(comm);
DataSet shop=new DataSet();
adapter.Fill(shop);

XmlDocument cdoc = new XmlDocument();
cdoc.LoadXml(shop.GetXml());
于 2012-06-26T10:15:24.410 回答