在c# aps.net 使用dataset 运行crystal report-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 155302
  • 博文数量: 11
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 170
  • 用 户 组: 普通用户
  • 注册时间: 2020-07-22 17:26
个人简介

blender https://www.blender-3d.cn/ blender3d模型库

文章分类

(11)

  • (1)
  • (0)
  • (0)
  • (1)
  • (1)
  • (1)
  • (1)
  • (2)
  • (2)
  • (2)
  • (0)
  • (0)
  • (0)
  • (0)
  • (0)
文章存档

(11)

我的朋友
最近访客
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: c#/.net

2020-07-27 16:48:41

1. 先建立一个只有资料行但没有连结资料库的dataset 

2. 建立一个crystal report 并使用projectdata > ado.net dataset 连接刚才新开的dataset

3.新增一个webform 并加入button ,crystalreportviewer,textbox

点击(此处)折叠或打开

  1. <%@ page language="c#" autoeventwireup="true" codefile="crystaltest4.aspx.cs" inherits="crystaltest4" %>

  2. <%@ register assembly="crystaldecisions.web, version=13.0.4000.0, culture=neutral, publickeytoken=692fbea5521e1304" namespace="crystaldecisions.web" tagprefix="cr" %>

  3. <!doctype html>

  4. <html xmlns="">
  5. <head runat="server">
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  7.     <title></title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.         <div>
  12.             <asp:textbox id="textbox1" runat="server"></asp:textbox>
  13.         <asp:button id="button1" runat="server" text="button" onclick="button1_click" />
  14.             <cr:crystalreportviewer id="crystalreportviewer1" runat="server" autodatabind="true" />
  15.         </div>
  16.         
  17.     </form>
  18. </body>
  19. </html>
4. 在.cs 加入以下代码

点击(此处)折叠或打开

  1. using system;
  2. using system.collections.generic;
  3. using system.linq;
  4. using system.web;
  5. using system.web.ui;
  6. using system.web.ui.webcontrols;
  7. using crystaldecisions.crystalreports.engine;
  8. using system.data;
  9. using system.data.sqlclient;
  10. using crystaldecisions.shared;
  11. public partial class crystaltest4 : system.web.ui.page
  12. {
  13.     protected void page_load(object sender, eventargs e)
  14.     {
  15.       

  16.         reportdocument rd = new reportdocument();
  17.         string reportpath = server.mappath("crystalreport4.rpt");


  18.         dataset ds = insertrecord();
  19.         rd.load(reportpath);

  20.         rd.setdatasource(ds);

  21.         this.crystalreportviewer1.reportsource = rd;
  22.      
  23.     }
  24.     private dataset insertrecord()
  25.     {
  26.         string constr = @"data source = 127.0.0.1; initial catalog = xxxx_db; persist security info = true; user id = xxx_dbuser; password =$xxxx";

  27.         using (sqlconnection con = new sqlconnection(constr))
  28.         {
  29.             using (sqlcommand cmd = new sqlcommand("select * from tbl_ole where id='" textbox1.text "'"))

  30.             {

  31.                 using (sqldataadapter sda = new sqldataadapter())
  32.                 {
  33.                     cmd.connection = con;
  34.                     sda.selectcommand = cmd;
  35.                     using (dataset ds = new dataset())
  36.                     {
  37.                         sda.fill(ds, "datatable1");
  38.                         return ds;
  39.                     }
  40.                 }


  41.             }




  42.         }



  43.     }

  44.     protected void button1_click(object sender, eventargs e)
  45.     {
  46.        

  47.         reportdocument rd = new reportdocument();
  48.         string reportpath = server.mappath("crystalreport4.rpt");

  49.         
  50.         dataset ds = insertrecord();
  51.         rd.load(reportpath);

  52.         rd.setdatasource(ds);
  53.        
  54.         this.crystalreportviewer1.reportsource = rd;
  55.      
  56.     }
  57. }
5. 在textbox 输入id 及按button, 就可出现所选资料
阅读(91970) | 评论(0) | 转发(1) |
0

上一篇:

下一篇:

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图