在SQL Server报表生成器中创建报表。都好!试图将其带入ReportViewer
,但写入错误
对于数据源'DataSet1'尚未设置数据源的实例。
代码:
private void button1_Click(object sender, EventArgs e)
{
reportViewer1.LocalReport.ReportPath = @"C:\MyReport.rdl";
reportViewer1.ProcessingMode = ProcessingMode.Local;
ReportParameter rp = new ReportParameter("code","100");
reportViewer1.LocalReport.SetParameters(rp);
this.reportViewer1.RefreshReport();
}
reportViewer1.LocalReport.DataSources
为空。为什么?在Report Builder中,一切都很好
XML MyReport
<DataSources>
<DataSource Name="NL">
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>Data Source=ACH\SQLEXPRESS;Initial Catalog=NL</ConnectString>
</ConnectionProperties>
<rd:SecurityType>DataBase</rd:SecurityType>
<rd:DataSourceID>629e3b49-aebf-48dc-bb89-f47956feaef8</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>NL</DataSourceName>
<QueryParameters>
<QueryParameter Name="@code">
<Value>=Parameters!code.Value</Value>
</QueryParameter>
</QueryParameters>
<CommandText>SELECT
window.code
,window.window
,window.[user]
FROM
window
WHERE
window.code < @code</CommandText>
答案 0 :(得分:0)
不,您不应该在客户端上使用ServerReport
选项。您应该分两步从服务器下载报告数据:
rdlc
格式生成报告数据源为DataSet
,并以编程方式设置数据源,如下所示:
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.SetParameters(GetReportParameters(parameter));
foreach (var source in ResultDataSet.Tables)
{
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(source.Name, source);
}