我所做的只是建立在形式的ReportViewer,然後我有這樣的代碼:創建數據集動態,並傳遞到的ReportViewer
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=G:\I.S\C#\billingSystem\Store.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
private void Form1_Load()
{
runRptViewer();
cn.Open();
}
private void rptGetDataset()
{
DataSet ds = new DataSet();
ds.DataSetName = "dsNewDataSet";
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NewBill", cn);
ds.GetXmlSchema();
da.Fill(ds);
ds.WriteXmlSchema(@"G:\I.S\Testoooooooo\Testoooooooo\Dataset1.xsd");
ds.WriteXml(@"G:\I.S\Testoooooooo\Testoooooooo\Dataset1.xml");
}
private DataTable getData()
{
DataSet dss = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NewBill", cn);
da.Fill(dss);
DataTable dt = dss.Tables["NewBill"];
return dt;
}
private void runRptViewer()
{
this.reportViewer2.Reset();
//this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
this.reportViewer2.LocalReport.ReportPath =(@"G:\I.S\Testoooooooo\Testoooooooo\Report1.rdlc");
ReportDataSource rds = new ReportDataSource("dsNewDataSet_NewBill", getData());
this.reportViewer2.LocalReport.DataSources.Clear();
this.reportViewer2.LocalReport.DataSources.Add(rds);
//this.reportViewer2.DataBind();
this.reportViewer2.LocalReport.Refresh();
}
}
我有兩個的ReportViewer的reportViewer1工作,但如果DB的目錄已經改變它不會工作,所以這就是爲什麼我嘗試在另一個reportViewer,即使DB的目錄改變,使其工作,我可以改變連接字符串。
的問題是該報告不顯示任何東西,我覺得在代碼中的問題:
//this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
這是一個Windows窗體所以沒有服務器,香港專業教育學院將其更改爲:
this.reportViewer2.LocalReport.ReportPath =(@"G:\I.S\Testoooooooo\Testoooooooo\Report1.rdlc");
,這一個不工作:
//this.reportViewer2.DataBind();
我無法理解這兩條線,這是否意味着創建一個數據集1.xsd和Dataset1.xml,或者只是編輯它們。 ds.WriteXmlSchema(@「G:\ I.S \ Testoooooooo \ Testoooooooo \ Dataset1.xsd」); ds.WriteXml(@「G:\ I.S \ Testoooooooo \ Testoooooooo \ Dataset1.xml」);如果可能的話,我需要從創建每一件事來編碼,這將是偉大的步驟。