Chinaunix首页 | 论坛 | 博客
  • 博客访问: 95056
  • 博文数量: 11
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 170
  • 用 户 组: 普通用户
  • 注册时间: 2020-07-22 17:26
个人简介

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

文章分类

全部博文(11)

文章存档

2020年(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="http://www.w3.org/1999/xhtml">
  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, 就可出现所选资料
阅读(81083) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~