这个问题折磨了我一天,坐的我屁股疼。
问这个问题的人很多,不知道是否适用,仅供参考哈。
1 public partial class _Default : System.Web.UI.Page
2 {
3 DataSet1 ds = new DataSet1();
4 private ReportDocument myreport;
5 protected void Page_Load(object sender, EventArgs e)
6 {
7 Button1_Click(sender, e);
8 }
9 protected void Button1_Click(object sender, EventArgs e)
10 {
11 myreport = new ReportDocument();
12 string reportPath = Server.MapPath("CrystalReport.rpt");
13 myreport.Load(reportPath);
14
15
16 string strProvider = "server=localhost;packet size=4096;user id=XXX;initial catalog=XXX;persist security info=True;password=XXXX";
17 SqlConnection MyConn = new SqlConnection(strProvider);
18 MyConn.Open();
19 string strSel = "Select a.bookno,a.cname,b.gname from [order] a,orderdetail b where a.bookno = b.bookno";
20 SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, MyConn);
21 DataSet ds = new DataSet();
22 MyAdapter.Fill(ds, "DataTable1");
23 myreport.SetDataSource(ds);
24
25 Viewer.ReportSource = myreport;
26 }
27
28 }
29
2 {
3 DataSet1 ds = new DataSet1();
4 private ReportDocument myreport;
5 protected void Page_Load(object sender, EventArgs e)
6 {
7 Button1_Click(sender, e);
8 }
9 protected void Button1_Click(object sender, EventArgs e)
10 {
11 myreport = new ReportDocument();
12 string reportPath = Server.MapPath("CrystalReport.rpt");
13 myreport.Load(reportPath);
14
15
16 string strProvider = "server=localhost;packet size=4096;user id=XXX;initial catalog=XXX;persist security info=True;password=XXXX";
17 SqlConnection MyConn = new SqlConnection(strProvider);
18 MyConn.Open();
19 string strSel = "Select a.bookno,a.cname,b.gname from [order] a,orderdetail b where a.bookno = b.bookno";
20 SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, MyConn);
21 DataSet ds = new DataSet();
22 MyAdapter.Fill(ds, "DataTable1");
23 myreport.SetDataSource(ds);
24
25 Viewer.ReportSource = myreport;
26 }
27
28 }
29
注意MyAdapter.Fill(ds, "DataTable1"); 这里的DataTable1必须与创建的Dataset1中的表名相同,否则会出现
The report you requested requires further information 信息。写成MyAdapter.Fill(ds);也不行。
祝好运!