如何从xml字符串生成rdlc报告?

问题描述

我正在尝试使用asp.net c#使用XML字符串作为数据源来制作报表查看器(RDLC REPORT) 这是xml

"<Data><Result>success</Result><Rowset><Row><Date>08-09-2020</Date><TrNo>2015</TrNo><Debit>355</Debit><Credit></Credit><Remark>rem in 2020015-500 USD/Commession</Remark><Balance>-809.5</Balance></Row></Rowset></Data>"  

所以我添加一个名为st_DS的数据集

this is a photo for the dataset

还创建了rdlc报告 rdlc report

添加了以下代码

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>  
      <rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer> 

这是背后的代码

string xml_resp = objCmd.Parameters["p_out"].Value.ToString();  
        XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(xml_resp));  
        st_DS stt = new st_DS();  
        stt.readxml(new XmlTextReader(new System.IO.StringReader(xml_resp)));   
        ReportViewer1.ProcessingMode = ProcessingMode.Local;  
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("st.rdlc");  
        ReportViewer1.LocalReport.DataSources.Clear();             
        ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("st_DS",stt.Tables[0])); 
        ReportViewer1.LocalReport.Refresh();  

当我运行代码时,它给我一个空白报告,没有数据 the text inside the red box is the response i got (XML)

任何人都可以帮助我,我很困惑!谢谢

解决方法

我找到了解决方案 只需添加以下数据集

 Dataset ds = new Dataset();
    ds.ReadXml(new XmlTextReader(new System.IO.StringReader(xml_resp)));
     ReportDataSource datasource = new ReportDataSource("st_DS",ds.Tables["Row"]); 

我必须在报表数据源处合并这两个数据集才能使其正常工作!