1
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中獲得價值。帶2參數的RDLC報告(存儲過程)
爲什麼呢?你給報表一個空表,然後_then_調用將數據導入到_another_表中的方法。 – DonBoitnott
你能幫我一下代碼嗎? –