C#操作数据库
来源:互联网 发布:mac ai 锁定快捷键 编辑:程序博客网 时间:2024/05/09 13:19
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace WindowsApplication2
...{
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.DataGrid dg1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Data.SqlClient.SqlConnection cn;
private SqlCommand cmd;
private SqlDataAdapter da;
private DataSet ds;
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
cn=new SqlConnection("server=xx007;uid=sa;pwd=sa;database=pubs");
cn.Open();
cmd.Connection=cn;
cmd.CommandText="select * from jobs";
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.dg1 = new System.Windows.Forms.DataGrid();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
((System.ComponentModel.ISupportInitialize)(this.dg1)).BeginInit();
this.SuspendLayout();
//
// dg1
//
this.dg1.DataMember = "";
this.dg1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dg1.Location = new System.Drawing.Point(0, 0);
this.dg1.Name = "dg1";
this.dg1.Size = new System.Drawing.Size(544, 296);
this.dg1.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(552, 301);
this.Controls.Add(this.dg1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dg1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace WindowsApplication2
...{
/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
...{
private System.Windows.Forms.DataGrid dg1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Data.SqlClient.SqlConnection cn;
private SqlCommand cmd;
private SqlDataAdapter da;
private DataSet ds;
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
...{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
cn=new SqlConnection("server=xx007;uid=sa;pwd=sa;database=pubs");
cn.Open();
cmd.Connection=cn;
cmd.CommandText="select * from jobs";
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.dg1 = new System.Windows.Forms.DataGrid();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
((System.ComponentModel.ISupportInitialize)(this.dg1)).BeginInit();
this.SuspendLayout();
//
// dg1
//
this.dg1.DataMember = "";
this.dg1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dg1.Location = new System.Drawing.Point(0, 0);
this.dg1.Name = "dg1";
this.dg1.Size = new System.Drawing.Size(544, 296);
this.dg1.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(552, 301);
this.Controls.Add(this.dg1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dg1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
...{
Application.Run(new Form1());
}
}
}
- C#数据库操作
- C#数据库操作
- C#操作ACCESS数据库
- C#数据库操作类
- C#操作数据库总结
- c#操作ACCESS数据库
- C#数据库操作
- C#数据库操作
- C#操作DBF数据库
- C#中数据库操作
- c#数据库操作类
- C#操作ACCESS数据库
- C#数据库操作类
- C#操作数据库
- c#操作Access数据库
- C# 操作ACCESS数据库
- C# 操作ACCESS数据库
- C#操作Sybase数据库
- 高低字节
- 今天遇到一个关于Hibernate程序的异常!请高手帮我解决下!!
- 如何用InputStream作为BIRT的xml数据源
- 网页中出现的动态背景(未解决)
- 第一篇
- C#操作数据库
- 闲谈orm(Object-Relational Mapping 对象-关系映射)
- tdh
- 程序员的基本素质
- 中国网通用户数上月净减76万 中国电信减75万(转)
- java中多态的学习。
- C#如何取得当前路径的函数
- 数据库中主键的作用
- Modelsim 5.6 se 简易使用教程