我所做的只是在表单中创建一个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可以工作,但是如果数据库的目录发生变化,它将无法工作,这就是为什么我尝试在另一个reportViewer中,即使数据库的目录发生变化也让它工作,我可以改变连接细绳。
问题是报告没有显示任何内容,我认为代码中的问题:
//this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
这是一个 Windows 窗体,因此没有服务器,我将其更改为:
this.reportViewer2.LocalReport.ReportPath =(@"G:\I.S\Testoooooooo\Testoooooooo\Report1.rdlc");
而这个不起作用:
//this.reportViewer2.DataBind();
我无法理解这两行,这是否意味着创建 Dataset1.xsd 和 Dataset1.xml,或者只是编辑它们。ds.WriteXmlSchema(@"G:\IS\Testoooooooo\Testoooooooo\Dataset1.xsd"); ds.WriteXml(@"G:\IS\Testoooooooo\Testoooooooo\Dataset1.xml"); 如果可能的话,我需要一个从创造每一件事到编码的步骤,这将是很棒的。