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;
  • 相关阅读:
    ZOJ 2158 Truck History
    Knight Moves (zoj 1091 poj2243)BFS
    poj 1270 Following Orders
    poj 2935 Basic Wall Maze (BFS)
    Holedox Moving (zoj 1361 poj 1324)bfs
    ZOJ 1083 Frame Stacking
    zoj 2193 Window Pains
    hdu1412{A} + {B}
    hdu2031进制转换
    openjudge最长单词
  • 原文地址:https://www.cnblogs.com/luoyaqi/p/3026310.html
Copyright © 2011-2022 走看看