VS2010 水晶报表的使用方法

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了VS2010 水晶报表的使用方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
在VS2010中新建一个“Windows 窗体应用程序”项目,在该项目中添加一个水晶报表“CrystalReport1.rpt”,然后在项目上点击鼠标右键属性,将“目标框架”改为“.Net Framework 4”

2013-06-20_003334

打开app.config文件,在“startup”节点一个“useLegacyV2RuntimeActivationpolicy="true"”属性

复制代码 代码如下:

<startup useLegacyV2RuntimeActivationPolicy="true">
&nbsp;   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

在Form1窗体中,从工具箱拖出一个Crystal Report Viewer控件,双击Form窗体,是双击Form窗体,不是Crystal Report Viewer,在后台的Form_Load事件中写入如下代码:

复制代码 代码如下:

PRivate void Form1_Load(object sender, Eventargs e)
        {
            string connStr = "Data Source=.\\SQLExPress;InITial CataLOG=dbtest;User ID=sa;Password=test";
            SqlConnection conn = new SqlConnection(connStr);
            conn.OPEn();
            try
            {
                string sql = "SELECT * From Customer where email!='test@gmail.COM'";
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds, "tmpTable");

                string reportPath = System.Windows.Forms.Application.StartupPath + @"\CrystalReport1.rpt";
                ReportDocument rd = new ReportDocument();
                rd.Load(reportPath);
                rd.SetDataSource(ds.Tables[0].DefaultView);
                this.crystalReportViewer1.ReportSource = rd;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }

这样就OK了

2013-06-19_234029

脚本宝典总结

以上是脚本宝典为你收集整理的VS2010 水晶报表的使用方法全部内容,希望文章能够帮你解决VS2010 水晶报表的使用方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: