通过动态数据表创建Crystal报表 [英] Create Crystal Report through Dynamic DataTable

查看:73
本文介绍了通过动态数据表创建Crystal报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我通过动态数据表制作了一个水晶报表.
但是,当它绑定时,我得到一个错误这里需要一个数字字段或货币金额字段".我检查了绑定在Crystal Report字段中的数据表的数据类型.

看到这一点,首先我制作了DataTable,如

Hello
I make a crystal report through Dynamic DataTable.
But when it bind then I get an error "a number field or currency amount field is required here". I checked datatype of datatable which I bind in crystal report fields.

See this, first I made DataTable like

string type = "Gov";
            sqlSelect = "select AI_PerEntry_ID,AI_Center_Name,AI_District,AI_Date,AI_Fresh_No_Of_Bull,AI_Repeat_No_Of_Bull,AI_Male_Calf,AI_Female_Calf,AI_Type from tbl_PerformanceEntry where AI_Type='" + type + "'";
            dt = cls.FetchDataTable(sqlSelect);
            DataTable table = new DataTable("AI_Performance");
            //Creating columns
            DataColumn column = new DataColumn("id");
            DataColumn column2 = new DataColumn("Center");
            DataColumn column3 = new DataColumn("District");
            DataColumn column4 = new DataColumn("No_of_Fresh");
            DataColumn column5 = new DataColumn("No_of_Repeat");
            DataColumn column6 = new DataColumn("Totle_Insemination");
            DataColumn column7 = new DataColumn("Calf_Birth(M/F)");
            // DataColumn column8 = new DataColumn("Female_Calf");
        
            table.Columns.Add(column);
            table.Columns.Add(column2);
            table.Columns.Add(column3);
            table.Columns.Add(column4);
            table.Columns.Add(column5);
            table.Columns.Add(column6);
            table.Columns.Add(column7);
          
            for (int i = 0; i < dt.Rows.Count; i++)
            {


                int Id = Convert.ToInt32(dt.Rows[i][0]);
                string center = dt.Rows[i][1].ToString();
                string district = dt.Rows[i][2].ToString();

                int f = Convert.ToInt32(dt.Rows[i][4]);
                int r = Convert.ToInt32(dt.Rows[i][5]);
                int c = (f + r);
                if (dt.Rows[i][6] == DBNull.Value || dt.Rows[i][7] == DBNull.Value)
                {
                    MC = 0;
                    FC = 0;
                }
                else
                {
                    MC = Convert.ToInt32(dt.Rows[i][6]);
                    FC = Convert.ToInt32(dt.Rows[i][7]);
                }
               
                DataRow row = table.NewRow();
                row["id"] = Id;
                row["Center"] = center;
                row["District"] = district;
                row["No_of_Fresh"] = f;
                row["No_of_Repeat"] = r;
                row["Totle_Insemination"] = c;
                row["Calf_Birth(M/F)"] = MC + " / " + FC;
              
                table.Rows.Add(row);
               
            }
          
            AI_Performance aiperformance = new AI_Performance();
            aiperformance.dtr = table;
            aiperformance.Show();


然后将其绑定为REPORT VIEWER"AI_Performance".


and then bind it REPORT VIEWER "AI_Performance".

////////This is my report viewer///
public DataTable dtr = new DataTable();

        public AI_Performance()
        {
            InitializeComponent();
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            Reports.AI_Performance crt = new Reports.AI_Performance();
           
            crt.Database.Tables[0].SetDataSource(dtr);
            crystalReportViewer1.ReportSource = crt;
            
        }
///////////


我认为我在绑定数据表时遇到了一些数据类型问题.这就是为什么我会收到在此需要数字字段或货币金额字段"错误的原因.
请您告诉我如何解决.非常感谢您.


I think I have a problem in binding of datatable where some datatype problem. That''s why I get that error "a number field or currency amount field is required here".

Kindly you can tell me how to solve it. I am very thankful to you.

推荐答案

我用另一种方式解决了它.
我是这样的
当我当时在datarow中绑定数据时,我将所有值插入另一个temp中.表,从该表中我绑定了reportview.
很简单,我得到了我的结果.

感谢所有查看和回复的人
i solved it with another way.
i do it like this
When i was binding a data in datarow in that time i insert all value in another temp. table, from that table i bind my reportview.
simple i got my results.

Thx for all who view and reply


这篇关于通过动态数据表创建Crystal报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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