源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

VS2010 水晶报表的使用方法

  • 时间:2020-09-21 12:24 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:VS2010 水晶报表的使用方法
在VS2010中新建一个“Windows 窗体应用程序”项目,在该项目中添加一个水晶报表“CrystalReport1.rpt”,然后在项目上点击鼠标右键属性,将“目标框架”改为“.Net Framework 4” [img]http://files.jb51.net/file_images/article/201306/2013062818294721.jpg[/img] 打开app.config文件,在“startup”节点一个“useLegacyV2RuntimeActivationPolicy="true"”属性
[u]复制代码[/u] 代码如下:
<startup useLegacyV2RuntimeActivationPolicy="true">     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup>
在Form1窗体中,从工具箱拖出一个Crystal Report Viewer控件,双击Form窗体,是双击Form窗体,不是Crystal Report Viewer,在后台的Form_Load事件中写入如下代码:
[u]复制代码[/u] 代码如下:
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了 [img]http://files.jb51.net/file_images/article/201306/2013062818294722.jpg[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部