我有一份报告表格" Form1ReportSale"。在它的加载事件中,我想根据来自另一个表单的ID生成RDLC报告。当我将程序置于调试模式时,DataSet返回预期值但会引发错误。
我的" Form1ReortSale"加载事件代码如下:
public partial class Form1ReportSale : Form
{
string CS;
private string id;
public string UserID
{
get { return id; }
set { id = value; }
}
public Form1ReportSale()
{
InitializeComponent();
CS = ConfigurationManager.ConnectionStrings["BikeDB"].ConnectionString;
}
private void Form1ReportSale_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
//DataSet1NewCustomerBike dsCustomers = GetData(id);
reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = @"E:\Working Area\Directorate Of IT Project\Own Practices\BikeShowRoom\BikeShowRoom\Reports\Form1ReportSale.cs";
DataSet ds = new DataSet();
ds = getDataByID(Convert.ToInt32(id));
ReportDataSource datasource = new ReportDataSource("DataSet1Customer",ds.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(datasource);
reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport();
}
private DataSet getDataByID(int ID)
{
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SELECT * FROM AddNewBike WHERE ID = '"+ID+"'", con);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
con.Open();
ad.Fill(ds);
}
return ds;
}
}
答案 0 :(得分:1)
查看您提供的路径:
reportViewer1.LocalReport.ReportPath = @"E:\Working Area\Directorate Of IT Project\Own Practices\BikeShowRoom\BikeShowRoom\Reports\Form1ReportSale.cs";
Form1ReportSale报告扩展名应为.rdlc而不是.cs ...复制您提供给报告的正确名称...或尝试使用此名称
reportViewer1.LocalReport.ReportPath = "~/Reports/Form1ReportSale.rdlc";