我在crstal Report中如何动态连接数据库
这些代码是在crystalReportViewer的Loan()里加吗?
我是新手,还望各位高手多多帮忙!谢谢!

解决方案 »

  1.   

    //打印
    //如果是要web打印只有cr10才可以实现
    public void printReport(string reportPath,DataSet reportSet,string PrinterPath,string passWrd)
    {
    ReportDocument  crystalReportObject=new ReportDocument();
    //crystalReportObject.
    crystalReportObject.Load(reportPath);//"e://temp//crt.rpt"
    //crystalReportObject.s
    crystalReportObject.SetDataSource(reportSet);
    crystalReportObject.Refresh();
    this.SetConnectionInfo(crystalReportObject,passWrd);
    //crystalReportObject.PrintOptions.PrinterName =@"\\office1\HP1000";
    crystalReportObject.PrintOptions.PrinterName =PrinterPath ;
    try
    {
    crystalReportObject.PrintToPrinter(1,false, 0, 0);
    }
    catch
    {
    ;
    }
    finally
    {
    crystalReportObject.Close();
    }
    //CrystalDecisions.Web.CrystalReportViewer myView=new CrystalDecisions.Web.CrystalReportViewer();
    //myView.LogOnInfo
    }
    public void printReport(string PrinterPath,ReportDocument crystalReportObject)
    { crystalReportObject.PrintOptions.PrinterName =PrinterPath ;
    try
    {
    crystalReportObject.PrintToPrinter(1,false, 0, 0);
    }
    catch(PrintException e)
    {
    DataPlatform.DataAccess.common.setMessage(e.ToString());
    ;
    }
    finally
    {
    crystalReportObject.Close();
    }
    //CrystalDecisions.Web.CrystalReportViewer myView=new CrystalDecisions.Web.CrystalReportViewer();
    //myView.LogOnInfo
    }
    这是网上的代码,我没具体试过,这些代码要写在你的打印按钮事件里!
      

  2.   

    连接数据库写在生成报表的时候,就是:连接数据库-->填充数据集-->(预览报表)-->打印
      

  3.   

    写在在页面加载或者水晶报表的VIEWER加载的时候或者你的触发按钮/事件里面都行,看你需要了,一般写CrystalReportViewer的Load里的比较多.