1
我有一個報告窗體「Form1ReportSale」。在它的加載事件中,我想根據來自另一個表單的ID生成RDLC報告。當我將我的程序置於調試模式時,DataSet會返回期望值,但會引發錯誤。RDLC-本地報告處理期間發生錯誤。報告定義無效
我 「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;
}
}
我改變了路徑。謝謝,但現在我得到一個錯誤'在本地報告處理期間發生錯誤','Microsoft.ReportingServices.ReportProcessing.ReportPrcoessingException:'此指定的操作無效。請幫我解決 –
試試這個......如果它不工作,那就告訴我..reportViewer1.LocalReport.ReportPath =「Form1ReportSale.rdlc」; –
我的數據表存在問題。當我運行查詢'select *'但我沒有在dataTable中設置幾個字段。無論如何謝謝,我正在標記你的問題 –