当前位置:编程学习 > C#/ASP.NET >>

各位,请帮忙看看,为什么我的报表不显示数据啊!!???

winform程序,连接access数据库,
新建了一个dataset 名称为tempDS,和一个datatable tempDT,
新建了一张报表,tempreport.rdlc,在rempreport.rdlc里面添加了一个表,
在button按钮中填写如下代码,运行后报表的表格中不显示数据,请各位给看看,谢谢了: 
using (OleDbConnection con = new OleDbConnection(constr))
            {
                //constr 前面已经定义
                OleDbCommand cmd=new OleDbCommand("select * from todaytemp",con);
                DataSet ds = new tempDS();
                con.Open();
                OleDbDataReader dr = cmd.ExecuteReader();
                ds.Tables[0].Load(dr);

               reportViewer1.LocalReport.ReportEmbeddedResource = "Door.tempreport.rdlc";
                ReportDataSource rds = new ReportDataSource();
                rds.Name = "tempDS_tempDT";
                rds.Value = ds.Tables[0];
                reportViewer1.LocalReport.DataSources.Add(rds);
                reportViewer1.RefreshReport();
             }
相关图片如下:


--------------------编程问答-------------------- 在线等!谢谢大家! --------------------编程问答-------------------- 都去吃饭了?? --------------------编程问答-------------------- --------------------编程问答-------------------- 我在.Net里用的水晶报表,跟你一样,采用PUSH模式.
参考阿泰的范例:
        //设置数据源信息
        DataSet1 ds1 = new DataSet1();
        OleDbDataAdapter da = new OleDbDataAdapter();
        String connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath ("~/app_data/test.mdb")+";";
        OleDbConnection cn = new OleDbConnection(connstr);


        //获取记录集,注意,最终获取的记录集需要与xsd的结构一致!
        //即使是子报表,也是同样的方法,因为这还是那个 Dataset!
        da = new OleDbDataAdapter("SELECT EmployeeId1 as EmployeeId,Hisdogname1 as Hisdog From forsubreport1", cn);
        //注意表名,需要与xsd中的一致!此处尽量不要忽略。
        da.Fill(ds1, "forsubreport");

        
        da = new OleDbDataAdapter("SELECT EmployeeId1 as EmployeeId,EmployeeName1 as EmployeeName From Employee1", cn);
        da.Fill(ds1, "Employee");

        da = new OleDbDataAdapter("SELECT ProductId1 as ProductId,ProductName1 as ProductName From Product1", cn);
        da.Fill(ds1, "Product");

        da = new OleDbDataAdapter("SELECT EmployeeId1 as EmployeeId,ProductId1 as ProductId,saledate1 as saledate,num1 as num From sales1", cn);
        da.Fill(ds1, "Sales");

        //以上为数据部分,与报表无关
        //-----------------------------------------------------------
        //以下为报表部分

        //使用报表对象加载报表
        ReportDocument myReport = new ReportDocument();
        string reportPath = Server.MapPath("~/app_data/crystalreport1.rpt");
        myReport.Load(reportPath);

        //CrystalReport1 myReport = new CrystalReport1();

        //绑定数据集,注意,一个报表用一个数据集。
        myReport.SetDataSource(ds1);
        CrystalReportViewer1.ReportSource = myReport;
--------------------编程问答-------------------- 你对照一下吧.我觉得 WinForm与 Web 的原理应该是一样的.
如果还不能解决问题.
去查一下阿泰的博客吧.
希望对你有所帮助. --------------------编程问答-------------------- 都去吃饭了?? 
--------------------编程问答-------------------- 谢谢,我感觉自己也是这样写的啊 --------------------编程问答-------------------- 到底那里出问题了啊?各位,走过路过,给看看呗 --------------------编程问答-------------------- 没人顶,自己顶,郁闷了 --------------------编程问答-------------------- 1、确保数据库表todaytemp与DataTable tempDT数据结构一致(字段名与类型)
2、修改你的代码如下(改动部分已用红色字体标出):
using (OleDbConnection con = new OleDbConnection(constr))
  {
  //constr 前面已经定义
  OleDbCommand cmd=new OleDbCommand("select * from todaytemp",con);
  tempDS ds = new tempDS(); 
  con.Open();
  OleDbDataReader dr = cmd.ExecuteReader();
  ds.tempDT.Load(dr);

  reportViewer1.LocalReport.ReportEmbeddedResource = "Door.tempreport.rdlc";
  ReportDataSource rds = new ReportDataSource();
  rds.Name = "tempDS_tempDT";
  rds.Value = ds.tempDT;
  reportViewer1.LocalReport.DataSources.Add(rds);
  reportViewer1.RefreshReport();
  } --------------------编程问答--------------------
引用 10 楼 luols 的回复:
1、确保数据库表todaytemp与DataTable tempDT数据结构一致(字段名与类型)
2、修改你的代码如下(改动部分已用红色字体标出):
using (OleDbConnection con = new OleDbConnection(constr))
  {
  //constr 前面已经定义
  OleDbCommand cmd=new OleDbCommand("sel……

谢谢老大,我去试试 --------------------编程问答--------------------
引用 10 楼 luols 的回复:
1、确保数据库表todaytemp与DataTable tempDT数据结构一致(字段名与类型)
2、修改你的代码如下(改动部分已用红色字体标出):
using (OleDbConnection con = new OleDbConnection(constr))
  {
  //constr 前面已经定义
  OleDbCommand cmd=new OleDbCommand("sel……

老大,还是不现实数据啊,todaytemp与DataTable tempDT数据结构我又核对了一遍,都一致的,表中的id是长整型,tempDT中int32、int64我都试了,其他字段都是string。
如果我在reportViewer1.LocalReport.DataSources.Add(rds);
前面加上一句reportViewer1.LocalReport.DataSources.clear();
报表则显示:尚未为数据源DataSet1 提供数据源示例”
这个DataSet1是在往报表里拖入table控件的时候,出现的选择数据源界面中的数据源名称。
--------------------编程问答-------------------- 你设断点跟踪一下 ds.tempDT有没数据 --------------------编程问答--------------------
引用 13 楼 luols 的回复:
你设断点跟踪一下 ds.tempDT有没数据

有数据的,
this.dataGridView1.DataSource = ds.tempDT;
这个datagridview能够完好显示数据 --------------------编程问答-------------------- 不要放在using里面,using后数据都被释放了 --------------------编程问答--------------------
引用 15 楼 luols 的回复:
不要放在using里面,using后数据都被释放了

还是不行,郁闷啊!
补充:.NET技术 ,  图表区
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,