先声明一个CrystalReport 的对象和DataSet 对象用SqlDataAdapter 的fill 方法填充DataSet 后将Dataset 绑定到CrystalReport ,用SetDataSource()方法即可,如果你想再绑定到查看器上crystalreportviewer1.ReportSource=CrystalReport对象

解决方案 »

  1.   

    给个例子吧,[email protected]
      

  2.   

    this.dbCnn=new SqlConnection(Base.Connectstring);this.dbCnn.Open();
    this.dbAdp=new SqlDataAdapter(sqlString,this.dbCnn);
    this.rptDs=new DataSet();
    this.dbAdp.Fill(this.rptDs,"V_BillService");
    this.SvcbillRpt=new Bill_rpt();
    this.SvcbillRpt.SetDataSource(this.rptDs);
    this.crv_main.ReportSource=this.SvcbillRpt;
    this.crv_main.DisplayGroupTree=false;其中,你报表设计的字段一定要与你sqlString 的字段 对应我想这样已经够清楚了吧!
      

  3.   

    有几个问题:Bill_rpt(); //是什么东西?
    SvcbillRpt  //就是那个报表控件名称?
    crv_main    //那这个是什么呢?
    查看器      //是什么?还有其它的什么器吗?我第一次使用,请详细点,把上面的问题说一下,就基本清楚了。
      

  4.   

    哈,我来猜谜语Bill_rpt(); //是什么东西?          //是他做的报表的一个实例
    SvcbillRpt  //就是那个报表控件名称?//是他在类里定义的类型为莫一已知报表的变量
    crv_main    //那这个是什么呢?      //是CrystalReportViewer吧
      

  5.   

    ReportDocument Rd = new ReportDocument();
    Rd.Load ("C:\\Inetpub\\wwwroot\\crm_vss02\\orgMng\\CRpt_khxx.rpt");
    /* 或则直接创建一个报表实例
      your_crystalReport Rd=new your_crystalReport();
    */TableLogOnInfo logOnInfo = new TableLogOnInfo ();
    logOnInfo.ConnectionInfo.ServerName ="ServerName"; //你自己的服务器名
    logOnInfo.ConnectionInfo.DatabaseName = "DBName"; //你自己的数据库名
    logOnInfo.ConnectionInfo.UserID ="UserName";//数据库用户名
    logOnInfo.ConnectionInfo.Password ="PassWord";//密码
    for(int i=0;i<Rd.Database.Tables.Count;i++)
    {
      Rd.Database .Tables [i].ApplyLogOnInfo (logOnInfo);
    }
    this.CrystalReportViewer1.ReportSource= Rd;