我有两个表
1,班级。 --->ID,年级,班别
2,学生。 --->学号,班级ID,姓名。我想由用户可以由“年级”,“班别”,“姓名”来查询结果
查询结果用水晶报表显示出来。。我已经把查找到的结果放在一个DataTable里了,请问如何将DataTable的数据绑定到水晶报表里显示出来呢?
 
请问有没有实例呢?

解决方案 »

  1.   

    你可以参考这个blog
    http://blog.163.com/wgchao_yt/blog/static/23359501200912033936592/
      

  2.   

    protected CrystalDecisions.Web.CrystalReportViewer RptView; 
    private SqlConnection myConnection; private void Page_Load(object sender, System.EventArgs e) 

    // 在此处放置用户代码以初始化页面 
    myConnection=new SqlConnection("server=127.0.0.0;database=temp;user id=sa;password=123"); 
    myConnection.Open(); 
    string strSql="select * from user "; 
    SqlCommand myCommand=new SqlCommand(); 
    myCommand.Connection=myConnection; 
    myCommand.CommandType=CommandType.Text; 
    myCommand.CommandText=strSql; 
    SqlDataAdapter myAd=new SqlDataAdapter(); 
    myAd.SelectCommand=myCommand; 
    DataSet myDs=new DataSet(); myAd.Fill(myDs,"tbUser"); 
    Report1 tmprpt=new Report1() ; //申明一个报表的实例 ,Report1.rpt 利用crystal report 生成 
    tmprpt.SetDataSource(myDs); 
    RptView.ReportSource=tmprpt; // CrystalReportViewer 设定 source就可以了 
    myCommand.Dispose(); 
    myAd.Dispose(); 
    myConnection.Close(); 
    }
      

  3.   


    请问子夜,当我运行到tmprpt.SetDataSource(myDs); 时,有错误,信息是:The report has no tables。请问在aspx里的代码,方便发一下不?麻烦你了。。
      

  4.   

    你检查以下你的myDs这个数据源,是否正确获取到数据