我把一个dataset绑定到一个报表时出错。 提示  该报表不包含表,既然我把dataset绑定到报表中,难道这报表中还要包含表吗?有人说  要给报表增加字段名,如果我给他增加字段名,我还要动态绑定干吗?即使增加字段名,那该如何加呢?

解决方案 »

  1.   

    转换类型? 什么意思?说具体点。俺 菜鸟+新手
    我就是要把它做gridview那样,通过SQL查询语句绑定数据。
      

  2.   

    呵呵,这个可不是一下能说清的哦.大概就是你要定义一个ttx文件,字段与你的ds一致.然后你再拖到rpt就OK.
    当然你在cs中还得写代码.
      

  3.   

            ReportDocument poRpt = new ReportDocument();
            poRpt.Load(Server.MapPath("CrystalReport1.rpt"));
            SqlDataAdapter sda = new SqlDataAdapter();
            string sql = "select * from DZLJ_03";
            SqlConnection con = new SqlConnection(Custom.SqlConnectionString);
            con.Open();
            sda.SelectCommand = new SqlCommand(sql,con);
            sda.SelectCommand.ExecuteNonQuery();
            con.Close();
            DataSet ds = new DataSet();
            sda.Fill(ds, "RepairRecord");
            poRpt.SetDataSource(ds);
            this.CrystalReportViewer1.ReportSource = poRpt;
    我是这样绑定的,我也不知道哪儿出了问题。请指教,谢谢!!
      

  4.   

    為什么不用report service 呢,這是vs 2005自帶,作用和水晶一樣哦
      

  5.   

    我按照有人说的把字段名拖进去,发现根本不需要dataset绑定就显示数据啦!! 
    高手们,帮忙想象办法,谢谢!!!!!!!!
      

  6.   

    加一行:
    poRpt.SetDataSource(myData);
    myData是你的数据集
      

  7.   

     加一句this.CrystalReportViewer1.DataBand();试试看
      

  8.   

     this.CrystalReportViewer1.DataBind();
      

  9.   

    你把con.Close();放在sda.Fill(ds,   "RepairRecord"); 后面
      

  10.   

    哥们 不是这个原因吧
    DataAdapter 是离线模式数据库操作!  还是谢谢你的回答!!
      

  11.   

    我会这样写
                    ReportDocument   poRpt   =   new   ReportDocument(); 
                    poRpt.Load(Server.MapPath("CrystalReport1.rpt"));                
                    string   sql   =   "select   *   from   DZLJ_03"; 
                    SqlConnection   con   =   new   SqlConnection(Custom.SqlConnectionString); 
                    SqlCommand command = new SqlCommand(sql,con);
                    SqlDataAdapter   sda   =   new   SqlDataAdapter(command); 
                    DataSet   ds   =   new   DataSet(); 
                    sda.Fill(ds);
                    poRpt.SetDataSource(ds); 
                    this.CrystalReportViewer1.ReportSource   =   poRpt; 
      

  12.   

    后面我换了个写法
             SqlDataAdapter sda = new SqlDataAdapter();
            string sql = "select * from DZLJ_03";
            SqlConnection con = new SqlConnection(Custom.SqlConnectionString);
            con.Open();
            sda.SelectCommand = new SqlCommand(sql, con);
            sda.SelectCommand.ExecuteNonQuery();
            con.Close();
            DataSet ds = new DataSet();
            sda.Fill(ds, "RepairRecord");
            CrystalReportSource1.ReportDocument.Load(Server.MapPath("CrystalReport.rpt"));
            //注意此处必需指明Dataset中的表的名称,否则会提示“您请求的报表需要更多信息.”
            CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]);
            CrystalReportSource1.DataBind();
            CrystalReportViewer1.ReportSource = CrystalReportSource1;
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.BestFitPage = true;
            CrystalReportViewer1.Width = Unit.Pixel(400);还是报 该报表中不包含表 的错误。  郁闷
    既然我用SQL语句绑定报,那报表中还要表干吗? 谁能解释下