关于C#.net中的Crystal Reports [英] Regarding Crystal Reports in C#.net

查看:64
本文介绍了关于C#.net中的Crystal Reports的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在C#Windows应用程序中工作.我的问题是,当我的数据库大小增加时,运行应用程序水晶报表时无法打开..否则它将正常运行..在Visual Studio 2005中不会发生此问题.但是我正在使用vs 2010 ..确切的问题是数据集'数据似乎没有正确设置为水晶报表的数据源,所以请任何人帮助我.

这是我的代码

Hi to all, I''m working in C# windows application. My problem is while running the application crystal report not opening when my database size increses.. otherwise it works fine.. this problem not occur in visual studio 2005.. but i''m using vs 2010.. the exact problem is dataset'' data not properly set to datasource of the crystal report it seems, so pls anyone help me..

this is my code

private void LoadUserReport()
        {
            try
            {
                
                ParameterFields _objParamFields = new ParameterFields();
                ParameterField _objParamField;
                ParameterDiscreteValue _objParamDiscreteValue;
                DataTable _dt = new DataTable();
                DataSet _ds1 = new DataSet();
                
                int iColumnNo = 0;
                for (int i = 0; i < _dsReport.Tables[0].Columns.Count; i++)
                {
                    string sColhead = _dsReport.Tables[0].Columns[i].ColumnName.Trim();
                    _dt.Columns.Add(sColhead);
                    userDS.Tables[0].Columns[i].AllowDBNull = true;
                }

                for (int i = 0; i < _dsReport.Tables[0].Rows.Count; i++)
                {
                    _dt.Rows.Add();
                    userDS.Tables[0].Rows.Add();
                    for (int k1 = 0; k1 < _dsReport.Tables[0].Columns.Count; k1++)
                    {
                        if (_dsReport.Tables[0].Rows[i][k1].ToString() != null)
                        {
                            _dt.Rows[i][k1] = _dsReport.Tables[0].Rows[i][k1].ToString();
                            userDS.userreport.Columns[k1].MaxLength = 1000;
                            string sStrValue = _dt.Rows[i][k1].ToString();
                            if (sStrValue != null)
                            {
                                userDS.userreport[i][k1] = sStrValue;
                            }
                        }
                    }
                }

                _ds1.Tables.Add(_dt);
                for (int i = 0; i < _dsReport.Tables[0].Columns.Count; i++)
                {
                    string colCaption = _dsReport.Tables[0].Columns[i].Caption.Trim();
                    _ds1.Tables[0].Columns[i].Caption = colCaption;
                }
                for (int k = 0; k < _ds1.Tables[0].Rows.Count; k++)
                {
                    for (int j = iColumnNo; j < _ds1.Tables[0].Columns.Count; j++)
                    {
                        iColumnNo++;
                        _objParamField = new ParameterField();
                        _objParamField.Name = "col" + iColumnNo;
                        _objParamDiscreteValue = new ParameterDiscreteValue();
                        if (_ds1.Tables[0].Rows[k][j].ToString() != null)
                        {
                            _objParamDiscreteValue.Value = _ds1.Tables[0].Columns[j].Caption.Trim();
                        }
                        _objParamField.CurrentValues.Add(_objParamDiscreteValue);
                        _objParamFields.Add(_objParamField);
                    }
                }
                for (int j = iColumnNo; j < 10; j++)
                {
                    iColumnNo++;
                    _objParamField = new ParameterField();
                    _objParamField.Name = "col" + iColumnNo;
                    _objParamDiscreteValue = new ParameterDiscreteValue();
                    _objParamDiscreteValue.Value = "";
                    _objParamField.CurrentValues.Add(_objParamDiscreteValue);
                    _objParamFields.Add(_objParamField);
                }
                

                crystalReportViewer1.ParameterFieldInfo = _objParamFields;                
                _objUserReport.SetDataSource(userDS);                   //here problem occur it seems
                             

                if (_sRptTitle.Trim().Length > 0)
                {
                    _objUserReport.SetParameterValue("Title", _sRptTitle.Trim() + "\t Report");
                }
                else
                {
                    _objUserReport.SetParameterValue("Title", "User Report");
                }
                if (_sLocationName != null)
                    _objUserReport.SetParameterValue("LocationName", _sLocationName.Trim());
                _objUserReport.SetParameterValue("Head1", _sEventHead1.Trim());
                _objUserReport.SetParameterValue("Head2", _sEventHead3.Trim());
                _objUserReport.SetParameterValue("Head3", _sEventHead4.Trim());
                Text = _sNewcon1;// "User Report";
                _objUserReport.SetParameterValue("Title", _sNewcon1);               
                
                crystalReportViewer1.ReportSource = _objUserReport;
                
            }
            catch (EngineException engex)
            {
                MessageBox.Show(engex.Message, _sMsgboxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

推荐答案

在行数超过1万的情况下,您是否检查过报表是否已完成从DB的数据访问?您可以在报告状态栏的左侧面板中对此进行验证.如果继续显示正在访问数据库",请检查该报表的SQL查询是否可以直接在您的数据库上正常运行.很可能是需要重新设计数据库的情况.包括索引(索引?).
Did you check that the report has actually completed the data access from your DB when you have more than 10k rows? You can verify this in the left panel of the status bar in the report. If it continues to say "Accessing Database", check that the report''s SQL query runs OK direct on your DB. It is, in all probability, a case of needing to re-design your database; including the indexes (indices?).


我认为DB端发生了超时(因为有更多记录),因此您应该优化DB端的操作.暂时增加数据库连接的超时.

另一种方法是更改​​PUSH model中的报告,但是我认为这对您来说是不可能的,因为您需要重新设计所有报告.
I think Timeout is happening(because more records) in your DB side so you should optimize the things in DB side. Temporarily increase the timeout for the database connection.

Another way is change the reports in PUSH model but I think it''s impossible to you because you need to redesign the all reports.


这篇关于关于C#.net中的Crystal Reports的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆