类库:https://files.cnblogs.com/ankoe/Fish.DataAccessLib.rar提供了数据库的连接设置接口
1
using System;
2
using System.Drawing;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Windows.Forms;
6
using System.Data;
7![]()
8
using Fish.DataAccessLib;
9
namespace TestLib
10
{
11
/// <summary>
12
/// Form1 的摘要说明。
13
/// </summary>
14
public class Form1 : System.Windows.Forms.Form
15
{
16
private System.Windows.Forms.DataGrid dataGrid1;
17
private ConnectionType ConnectionType1=new ConnectionType();
18
/// <summary>
19
/// 必需的设计器变量。
20
/// </summary>
21
private System.ComponentModel.Container components = null;
22![]()
23
public Form1()
24
{
25
//
26
// Windows 窗体设计器支持所必需的
27
//
28
InitializeComponent();
29![]()
30
//
31
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
32
//
33
}
34![]()
35
/// <summary>
36
/// 清理所有正在使用的资源。
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
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
53
/// 此方法的内容。
54
/// </summary>
55
private void InitializeComponent()
56
{
57
this.dataGrid1 = new System.Windows.Forms.DataGrid();
58
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
59
this.SuspendLayout();
60
//
61
// dataGrid1
62
//
63
this.dataGrid1.DataMember = "";
64
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
65
this.dataGrid1.Location = new System.Drawing.Point(48, 16);
66
this.dataGrid1.Name = "dataGrid1";
67
this.dataGrid1.Size = new System.Drawing.Size(200, 178);
68
this.dataGrid1.TabIndex = 0;
69
//
70
// Form1
71
//
72
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
73
this.ClientSize = new System.Drawing.Size(292, 266);
74
this.Controls.Add(this.dataGrid1);
75
this.Name = "Form1";
76
this.Text = "Form1";
77
this.Load += new System.EventHandler(this.Form1_Load);
78
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
79
this.ResumeLayout(false);
80![]()
81
}
82
#endregion
83![]()
84
/// <summary>
85
/// 应用程序的主入口点。
86
/// </summary>
87
[STAThread]
88
static void Main()
89
{
90
Application.Run(new Form1());
91
}
92![]()
93
private void Form1_Load(object sender, System.EventArgs e)
94
{
95
DataSet ds = SqlHelper.ExecuteDataset(ConnectionType1.SqlConnection,CommandType.Text,"select * from U_XtraColumnSet");
96
DataView dv = ds.Tables[0].DefaultView;
97
this.dataGrid1.DataSource = dv;
98
99
}
100
}
101
}
102![]()
using System;2
using System.Drawing;3
using System.Collections;4
using System.ComponentModel;5
using System.Windows.Forms;6
using System.Data;7

8
using Fish.DataAccessLib;9
namespace TestLib10
{11
/// <summary>12
/// Form1 的摘要说明。13
/// </summary>14
public class Form1 : System.Windows.Forms.Form15
{16
private System.Windows.Forms.DataGrid dataGrid1;17
private ConnectionType ConnectionType1=new ConnectionType();18
/// <summary>19
/// 必需的设计器变量。20
/// </summary>21
private System.ComponentModel.Container components = null;22

23
public Form1()24
{25
//26
// Windows 窗体设计器支持所必需的27
//28
InitializeComponent();29

30
//31
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码32
//33
}34

35
/// <summary>36
/// 清理所有正在使用的资源。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
/// 设计器支持所需的方法 - 不要使用代码编辑器修改53
/// 此方法的内容。54
/// </summary>55
private void InitializeComponent()56
{57
this.dataGrid1 = new System.Windows.Forms.DataGrid();58
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();59
this.SuspendLayout();60
// 61
// dataGrid162
// 63
this.dataGrid1.DataMember = "";64
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;65
this.dataGrid1.Location = new System.Drawing.Point(48, 16);66
this.dataGrid1.Name = "dataGrid1";67
this.dataGrid1.Size = new System.Drawing.Size(200, 178);68
this.dataGrid1.TabIndex = 0;69
// 70
// Form171
// 72
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);73
this.ClientSize = new System.Drawing.Size(292, 266);74
this.Controls.Add(this.dataGrid1);75
this.Name = "Form1";76
this.Text = "Form1";77
this.Load += new System.EventHandler(this.Form1_Load);78
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();79
this.ResumeLayout(false);80

81
}82
#endregion83

84
/// <summary>85
/// 应用程序的主入口点。86
/// </summary>87
[STAThread]88
static void Main() 89
{90
Application.Run(new Form1());91
}92

93
private void Form1_Load(object sender, System.EventArgs e)94
{95
DataSet ds = SqlHelper.ExecuteDataset(ConnectionType1.SqlConnection,CommandType.Text,"select * from U_XtraColumnSet");96
DataView dv = ds.Tables[0].DefaultView;97
this.dataGrid1.DataSource = dv;98
99
}100
}101
}102

SQL:
CREATE TABLE [U_XtraColumnSet] (
[AutoID] [int] IDENTITY (1, 1) NOT NULL ,
[cUser_ID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[cReport] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[bFieldKey] [bit] NULL ,
[iItemOrder] [int] NULL ,
[cFieldName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cTitle] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[bSelected] [bit] NULL ,
[iWidth] [int] NULL ,
[bReadOnly] [bit] NULL ,
[cSummaryType] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cGroupSummaryType] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cSummaryDispFormat] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cGroupSummaryDispFormat] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cAlignment] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cFormatString] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cFormatType] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO




浙公网安备 33010602011771号