如何将Datatable中的数据绑定到Crystal报表 [英] How to bind data in Datatable to Crystal report

查看:105
本文介绍了如何将Datatable中的数据绑定到Crystal报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在C#和Sqlite DB中开发了一个Windows窗体应用程序。 Applicatio有水晶报告&数据集我已将数据库字段中的表字段添加到水晶报表中。问题是当我运行应用程序值时,不会在水晶报表中显示仅显示字段名称。当我检查DataTable时,所选的行值在dt中。但我无法将其绑定到水晶报告以下是代码。



谢谢





Hi,
I have developed a windows Form application in C# and Sqlite DB. Applicatio have crystal Report & Dataset I have added table fields from Database field to crystal report. The problem is when I run the application values are not displayed in crystal report only Field names are displayed. When I check DataTable the selected row values are there in dt. but I can't bind that to crystal report following is the code.

Thank you


private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            this.crystalReportViewer1.RefreshReport();
            SQLiteConnection cn = new SQLiteConnection(sett.con);

            string BillPath = System.AppDomain.CurrentDomain.BaseDirectory;
            if (BillPath.EndsWith("\\bin\\Debug\\"))
            {
                BillPath = BillPath.Replace("\\bin\\Debug\\", "");
            }
            DataTable dt = new DataTable();
            
            SQLiteDataAdapter adp = new SQLiteDataAdapter("select * from tb_IO where ID=" + sett.Pr_id + " and case_id=" + sett.case_id, cn);
            adp.Fill(dt);
          
           
            Genflaw_report cryRpt = new Genflaw_report();
            BillPath = BillPath + "\\CrystalReport1.rpt";
            cryRpt.Load(BillPath);
            cryRpt.Database.Tables[0].SetDataSource(dt);
            
            cryRpt.Refresh();
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
            
        }

推荐答案

推荐这个



使用C#使用DataSet和DataTable的Crystal Report [ ^ ]


表名代码中的 DataTable名称应该相同。所以你的代码(声明)应该如下所示

Table's name from report & DataTable's name from code should be the same. So your code(declaration) should be like below
DataTable dt = new DataTable("tb_IO");//tb_IO is Table from your SQL query.


这篇关于如何将Datatable中的数据绑定到Crystal报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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