Data display in dataset after specifying parameters for stored procedure
RDLC report just display the report headers but no data
public partial class Form1 : Form
{
DataTable ResultsTable = new DataTable();
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
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)
{
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()
{
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
并为存储过程指定相同的参数,我会在网格中找回值。但我无法获得RDLC报告中的值。