下面是我的代码:
public void BindPrintView()
    {
        ConnDB conn = new ConnDB(strConn);
        ReportDocument Report = new ReportDocument();
        TableLogOnInfo logOnInfo = new TableLogOnInfo();
        Report.Load("path\\JobReport.rpt");        //为报表中的表设置连接信息。  
        logOnInfo.ConnectionInfo.ServerName = "mysevername";
        logOnInfo.ConnectionInfo.DatabaseName = "mydatabasename";
        logOnInfo.ConnectionInfo.UserID = "admin";
        logOnInfo.ConnectionInfo.Password = "mypsw";
        Report.Database.Tables[0].ApplyLogOnInfo(logOnInfo);        string str = "SELECT   *   FROM   table where id = '1044'";
        DataSet ds = conn.ReturnDataSet(str);
        Report.SetDataSource(ds.Tables[0]);
        CrystalReportViewer1.ReportSource = Report;
    }
问题:按照我上面的sql语句,应该报表显示的是id为1044的记录,但是为什么还是显示了table里所有数据,为何?

解决方案 »

  1.   

    另:在水晶报表设计时,用到了两个表,但上面的代码因为我是测试,所以在sql语句里只用了一个table,如果要两个表都动态绑定,应该怎么做?如下:SELECT   *   FROM table1 a ,table2  b  where  a.id = b.id and a.id = '1044',查看报表,显示效果是所有字段为空??
    第一次搞这个,不明白??请指教
      

  2.   

    string   strSel   =   "Select   *   from   employee   where   fname   like   'P%'";  
      SqlDataAdapter   MyAdapter   =   new   SqlDataAdapter(strSel,MyConn);  
      DataSet1   ds   =   new   DataSet1();//实例化数据集 
     
    MyAdapter.Fill(ds,"employee)         
    MyConn.Close();  
    reportDocument1.Load("d:\\Report.rpt");  
       
      reportDocument1.SetDataSource(ds);  
      this.CrystalReportViewer1.ReportSource   =   reportDocument1;  
                              CrystalReportViewer1.DataBind(); 
      

  3.   

    第二个问题:如果是两张或者多张表的话就用视图做,把视图绑定到报表里,然后在代码里绑定数据源的话也用视图:
    如:string sqlSearch="select * from union_view where .....";
    .....