注册 登录
编程论坛 ASP.NET技术论坛

水晶报表的问题

zhishiouran 发布于 2008-07-01 17:02, 760 次点击
怎么让水晶报表按条件执行,我用datagrid来查看某一条数据的报表,但是显示了全部数据,不知道为什么?
4 回复
#2
zhishiouran2008-07-01 17:03
private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            this.myRPDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

            
            if (!this.IsPostBack)        //页面首次加载时执行
            {
                                    
                string str="";                
                if (Request.QueryString["ID"]!=null)                //如果传递的参数不为空
                {
                    str=Request.QueryString["ID"].ToString();    //取出传递过来的参数ID
                    //BindData(str);
                    this.PageBind (str);
                    
                }    
            }
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {   
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
        private void PageBind(string str)
        {
            String   sqlComm = "select id,sq_department,sq_time,sq_people,shenhe_people,shenhe_time,pizhun_people,pizhun_time,excute_department,excute_time,wz_name,wz_xh,wz_danwei,sq_num,hezhun_num,beizhu from [lsh_cg_plan] where temp_cg_id = '"+str+"'";

            this.myRPDoc.Load( Server.MapPath( "CryReports/temp_caigou.rpt" ) );
            //SqlConnection myConn = new SqlConnection( "server=192.168.200.116;database=asset;User Id=sa;pwd=sa" );
            //string con = ConfigurationSettings.AppSettings["DBConnectionString"];
            string con = "server=(local);database=lyjxc;User id=sa;Pwd=''";
            SqlConnection myConn = new SqlConnection (con);
            myConn.Open ();
            DataSet myDs = new DataSet();
            this.getTableData( sqlComm,ref myDs,"lsh_cg_plan",myConn );
            this.myRPDoc.SetDataSource( myDs );
            this.CrystalReportViewer1.ReportSource = this.myRPDoc;
            this.CrystalReportViewer1.DataBind();
            myConn.Close ();
        }

        protected bool getTableData( String strCommand , ref DataSet myDataSet , String TableName , SqlConnection sqlConn )
        {
            bool returnValue = true;
            SqlCommand myCommand = new SqlCommand( strCommand,sqlConn );
            SqlDataAdapter myAdapter = new SqlDataAdapter( myCommand );
            try
            {
                myAdapter.Fill( myDataSet,TableName );
            }
            catch
            {
                returnValue = false;
            }
            return returnValue;
        }
#3
zhishiouran2008-07-02 13:16
怎么没人回答啊,急 啊
#4
hebingbing2008-07-02 18:53
  DataSet myDs = new DataSet();
            this.getTableData( sqlComm,ref myDs,"lsh_cg_plan",myConn );//这个函数本来是有返回值的,但是你好像没有用它的返回值啊,虽然这影响并不大……
            this.myRPDoc.SetDataSource( myDs );//这里你是不是应该用myDs中的lsh_cg_plan表的,既然要用这个表那为什么要用myDs呢?不知道你的myRPDoc.SetDataSource方法是怎么写的……
#5
zhishiouran2008-07-03 13:50
我没用这个myRPDoc.SetDataSource(),这个代码是拿别人的,我自己也没看懂是怎么回事,但是我看别人用的很好啊
1