小女在VS2008窗体工程中创建了一个Crystal Report,使用了“使用报表向导”创建的方法(如图1),然后使用了ADO本地SQL server2005数据库(如图2),最后制作了报表,可以进行预览(如图3),但是不能运行,这是为什么?怎么才能在窗体中运行水晶报表?

解决方案 »

  1.   

    用CrystalReportSource接受CrystalReportViewer的报表显示
      

  2.   

    页面上还需要 绑定数据和加载水晶报表。
    方法; 例如你新建一个页面 和报表控件
     SqlConnection mycon = sqlcls.constring();
            string sqlstr = "select * from students";
            sqlcls.sqlds(sqlstr, "students");        string sqlstr1 = "select * from Department";
            sqlcls.sqlds(sqlstr1, "Department");
                   CrystalReportSource1.ReportDocument.Load(Server.MapPath("MyCrystal.rpt"));
            //CrystalReportSource1.ReportDocument.SetDataSource();
            CrystalReportSource1.ReportDocument.SetDatabaseLogon("sa", "", "127.0.0.1", "students");        CrystalReportViewer1.ReportSource = CrystalReportSource1;
            CrystalReportViewer1.DataBind();