RDLC- 本地报告处理期间发生错误。报告定义无效
RDLC- An Error occurred during local report processing. The report definition is not valid
我有一份报告表"Form1ReportSale"。在它的加载事件中,我想根据来自另一个表单的 ID 生成 RDLC 报告。当我将我的程序置于调试模式时,DataSet returns 预期值但抛出错误。
请找附件
我的 "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;
}
}
检查您提供的路径:
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";
我有一份报告表"Form1ReportSale"。在它的加载事件中,我想根据来自另一个表单的 ID 生成 RDLC 报告。当我将我的程序置于调试模式时,DataSet returns 预期值但抛出错误。
请找附件
我的 "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;
}
}
检查您提供的路径:
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";