C#水晶报表数据获取方法实例浅析

开发 后端
C#水晶报表数据获取方法是什么呢?我们在实际的开发中是如何获取C#水晶报表数据呢?这里我们主要向你讲述了通过提取模式的方法来实现。

C#水晶报表数据获取方法有很多,那么这里主要向你介绍一个通过提取模式的方法来实现C#水晶报表数据获取方法,那么具体的实现步骤是什么呢?让我们看看具体的实现代码:

C#水晶报表数据获取方法实例演示:

  1. using System;  
  2. using System.Drawing;  
  3. using System.Collections;  
  4. using System.ComponentModel;  
  5. using System.Windows.Forms;  
  6. using CrystalDecisions.CrystalReports.Engine;  
  7. using CrystalDecisions.Shared;  
  8. namespace DLLCrystal  
  9. {  
  10. /// ﹤summary﹥  
  11. /// frmCrystalView 的摘要说明。  
  12. /// ﹤/summary﹥  
  13. internal class frmCrystalView : System.Windows.Forms.Form  
  14. {  
  15. private CrystalDecisions.Windows.Forms.CrystalReportViewer crView;  
  16. /// ﹤summary﹥  
  17. /// 必需的设计器变量。  
  18. /// ﹤/summary﹥  
  19. private System.ComponentModel.Container components = null;  
  20. private string[] strInfo;  
  21.  
  22. public frmCrystalView(string[] strInfomation)  
  23. {  
  24. //  
  25. // C#水晶报表数据的获取方法之Windows 窗体设计器支持所必需的  
  26. //  
  27. InitializeComponent();  
  28.  
  29. //  
  30. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码  
  31. //  
  32. strInfo=strInfomation;  
  33. }  
  34.  
  35. /// ﹤summary﹥  
  36. /// C#水晶报表数据获取方法之清理所有正在使用的资源。  
  37. /// ﹤/summary﹥  
  38. protected override void Dispose( bool disposing )  
  39. {  
  40. if( disposing )  
  41. {  
  42. if(components != null)  
  43. {  
  44. components.Dispose();  
  45. }  
  46. }  
  47. base.Dispose( disposing );  
  48. }  
  49.  
  50. #region Windows 窗体设计器生成的代码  
  51. /// ﹤summary﹥  
  52. /// C#水晶报表数据获取方法之设计器支持所需的方法 - 不要使用代码编辑器修改  
  53. /// 此方法的内容。  
  54. /// ﹤/summary﹥  
  55. private void InitializeComponent()  
  56. {  
  57. this.crView = new CrystalDecisions.Windows.Forms.CrystalReportViewer();  
  58. this.SuspendLayout();  
  59. //   
  60. // crView  
  61. //   
  62. this.crView.ActiveViewIndex = -1;  
  63. this.crView.Dock = System.Windows.Forms.DockStyle.Fill;  
  64. this.crView.Location = new System.Drawing.Point(0, 0);  
  65. this.crView.Name = "crView";  
  66. this.crView.ReportSource = null;  
  67. this.crView.ShowRefreshButton = false;  
  68. this.crView.Size = new System.Drawing.Size(640, 509);  
  69. this.crView.TabIndex = 0;  
  70. //   
  71. // frmCrystalView  
  72. //   
  73. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);  
  74. this.ClientSize = new System.Drawing.Size(640, 509);  
  75. this.Controls.Add(this.crView);  
  76. this.Name = "frmCrystalView";  
  77. this.Text = "预览报表";  
  78. this.Load += new System.EventHandler(this.frmCrystalView_Load);  
  79. this.ResumeLayout(false);  
  80.  
  81. }  
  82. #endregion  
  83.  
  84. private void frmCrystalView_Load(object sender, System.EventArgs e)  
  85. {  
  86. ReportDocument rdView=new ReportDocument();  
  87. rdView.Load(@strInfo[0]);  
  88. foreach (Table tbView in rdView.Database.Tables)  
  89. {   
  90. TableLogOnInfo tliView=new TableLogOnInfo();  
  91. tliView=tbView.LogOnInfo;  
  92. tliView.ConnectionInfo.ServerName=strInfo[1];  
  93. tliView.ConnectionInfo.DatabaseName=strInfo[2];  
  94. tliView.ConnectionInfo.UserID=strInfo[3];  
  95. tliView.ConnectionInfo.Password=strInfo[4];  
  96. tbView.ApplyLogOnInfo(tliView);  
  97. }  
  98.  
  99. string [] strParameter=strInfo[5].Split(new char[] {+});  
  100. for (int i=0;i﹤strParameter.Length;i++)  
  101. {  
  102. string [] strSubParam=strParameter[i].Split(new char[] {=});  
  103. ParameterValues pvValue=new ParameterValues();  
  104. ParameterDiscreteValue pdvValue=new ParameterDiscreteValue();  
  105. pdvValue.Value=strSubParam[1];  
  106. pvValue.Add(pdvValue);  
  107. rdView.DataDefinition.  
  108. ParameterFields[strSubParam[0]].ApplyCurrentValues(pvValue);  
  109. }  
  110. crView.ReportSource=rdView;  
  111. this.Location = new Point(0, 0);  
  112. this.Size = new System.Drawing.Size(1024,744);  
  113. }  
  114. }//C#水晶报表数据获取方法  
  115. }  

C#水晶报表数据获取方法的具体事宜就向你介绍到这里,希望那个对你了解和学习C#水晶报表数据获取方法有所帮助。

【编辑推荐】

  1. C#创建一个文件的具体实现浅析
  2. C#打开一个文件的操作详解
  3. C#实现string和byte数组的转换
  4. C# Byte数组转换String详解
  5. 详解C#调用水晶报表的实现
责任编辑:仲衡 来源: opent.cn
相关推荐

2009-08-31 15:11:23

C#调用水晶报表

2009-08-31 15:54:35

2009-07-30 13:57:39

ASP.NET水晶报表ASP.NET

2009-09-07 19:03:08

2009-11-05 14:03:28

Visual Stud

2009-07-29 09:29:06

ASP.NET水晶报表

2009-12-15 17:20:07

VS 水晶报表

2009-08-02 11:48:58

ASP.NET水晶报表ASP.NET

2009-10-16 13:30:51

VB.NET水晶报表控

2010-01-14 10:52:13

VB.NET水晶报表

2009-08-25 17:00:32

ASP.NET水晶报表

2009-08-31 16:09:42

.net水晶报表使用学

2009-08-27 13:30:11

C# interfac

2009-11-26 13:27:10

VS2003水晶报表

2009-12-01 13:50:19

VS2003水晶报表

2009-08-17 17:49:20

C# 枚举

2009-09-09 13:57:28

C# XML解析

2009-08-18 13:49:21

C# 操作Excel

2009-08-27 17:59:56

C#接口定义

2009-08-19 16:30:55

C#操作Access数
点赞
收藏

51CTO技术栈公众号