zoukankan      html  css  js  c++  java
  • 初遇vs2008做报表时 数据显示行数不对问题

    问题描述:

      之前我debug了程序 跟踪了dataset数据集里的数据(是查询出来要显示的数据),但当我用dataset对象填充到报表*.rpt的数据源后 

    跟踪调试后rpt报表里显示的数据只显示两行,无论怎么去修改查询sql语句也都有两条记录(我跟踪的是:int ttt = 报表对象.Rows.Count)

    解决方法:

         将OleDbDataAdapter.Fill(ds) 改为OleDbDataAdapter.Fill(ds,"student")得到解决;

         注意:OleDbDataAdapter.Fill(DataSet dataSet, string srcTable)其中srcTable用于表映射的源表的名称。

    代码如下:

    View Code
    //先查出数据装载到数据集DataSet2中
                DataSet2 ds = new DataSet2();
                string path = System.Windows.Forms.Application.StartupPath;
                string tmpPath = path.Substring(0, path.LastIndexOf("\\"));
                tmpPath = tmpPath.Substring(0, tmpPath.LastIndexOf("\\")) + "\\DB\\test.mdb";//获取数据库的位置
                string strCon = "Provider=Microsoft.Jet.OleDb.4.0; Data Source= ";
                strCon += tmpPath;
                using (OleDbConnection oldbCon = new OleDbConnection(strCon))
                {
                    oldbCon.Open();
                    OleDbCommand oldbCmd = new OleDbCommand(@"select * from student", oldbCon);
                    OleDbDataAdapter da = new OleDbDataAdapter(oldbCmd);
                    da.Fill(ds, "student");
                    oldbCon.Close();
                    oldbCmd.Dispose();
                    da.Dispose();
                }
    
                //设置报表的数据源
                CR_TEST2 cR = new CR_TEST2();
                cR.SetDataSource(ds);
                //int ttt = cR.Rows.Count;
    
                //设置窗口报表报表源
                crystalReportViewer1.ReportSource = cR;
  • 相关阅读:
    inflate用一个XML源填充view. LayoutInflater
    关于inflate的第3个参数
    关于inflate的第3个参数
    android ImageView scaleType属性
    android ImageView scaleType属性
    Android中设置文本颜色的三种方法
    JDK1.8与spring3.x的不兼容
    Spring整合activiti单元测试
    良好编程习惯的养成
    No output operations registered, so nothing to execute
  • 原文地址:https://www.cnblogs.com/luoyaqi/p/3026310.html
Copyright © 2011-2022 走看看