带有 2 个参数的 RDLC 报告(存储过程) [英] RDLC Report (Stored Procedure) with 2 Parameters
本文介绍了带有 2 个参数的 RDLC 报告(存储过程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'DataSet1.sp_GetRent1' table. You can move, or remove it, as needed.
this.sp_GetRent1TableAdapter.Fill(this.DataSet1.sp_GetRent1, "@RentNo1", "@AppPath");
//this.GetSPResult();
this.reportViewer1.RefreshReport();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
reportViewer1.Visible = true;
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1",dt));
GetSPResult();
}
private DataTable GetSPResult()
{
DataTable ResultsTable = new DataTable();
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=RentACar1;Integrated Security=True");// ProviderName = "System.Data.SqlClient");
try
{
SqlCommand cmd = new SqlCommand("sp_GetRent1",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@RentNo1", "9905-10-2017");
cmd.Parameters.AddWithValue("@AppPath", @"E:\Rent A Car\RentACar1\RentACar\bin\Debug");
conn.Open();
//cmd.ExecuteNonQuery();
SqlDataAdapter adaptor = new SqlDataAdapter(cmd);
adaptor.SelectCommand = cmd;
adaptor.Fill(ResultsTable);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return ResultsTable;
}
此代码在 RDLC 报告中没有显示任何内容.如果我打开 dataset1.xsd,并将相同的参数提供给 SP,我将获得网格中的值.但我无法在 RDLC 中获取值.
This code doesn't show me anything in RDLC report. If i open dataset1.xsd, and I give the same parameters to the SP, I get values in grid. But I am unable to get values in RDLC.
推荐答案
您的 button1_Click 应如下所示:
Your button1_Click should look like this:
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = GetSPResult();
reportViewer1.Visible = true;
reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new
Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt));
}
请注意,从 GetSPResult 返回的 DataTable 应添加到报告中,而不是像您的代码中那样新创建的空白表.
Note that the DataTable returned from GetSPResult should be added to the report not a newly created blank table as in yourt code.
这篇关于带有 2 个参数的 RDLC 报告(存储过程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文