水晶报表,拉模式成功,推模式失败。
今天用推模式做了几个水晶报表。前面几个都成功了。
但最后一个失败。
我将它改为拉模式,确能成功
推模式,就找不到数据源。
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection("server=.;database=test1;uid=sa;pwd=sa;"))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("select * from a", con))
{
cmd.CommandType = CommandType.Text;
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.Fill(ds, "a");
}
}
using (SqlConnection con = new SqlConnection("server=.;database=test1;uid=sa;pwd=sa;"))
{
using (SqlCommand cmd = new SqlCommand("select * from b", con))
{
cmd.CommandType = CommandType.Text;
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.Fill(ds, "b");
}
}
report = new ReportDocument();
string reportPath = Server.MapPath("~/Reports/test.RPT");
report.Load(reportPath);
report.SetDataSource(ds);
CrystalReportViewer1.ReportSource = report;
------解决方案--------------------
CrystalReportViewer1.ReportSource = report;
CrystalReportViewer1.DataBind();