| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 507 人关注过本帖
标题:关于C#的类!
只看楼主 加入收藏
zzrb
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2006-2-22
收藏
 问题点数:0 回复次数:1 
关于C#的类!
那位大侠能给讲讲C#的类?俺看书没有看明白,多多谢谢!
2006-02-22 21:27
ws001
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-3-14
收藏
得分:0 


using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication13
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Windows.Forms.DataGrid dataGrid1;
private WindowsApplication13.DataSet1 dataSet11;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection2;

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet11 = new WindowsApplication13.DataSet1();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection2 = new System.Data.SqlClient.SqlConnection();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.SuspendLayout();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=DMT;packet size=4096;user id=sa;integrated security=SSPI;data sour" +
"ce=dmt;persist security info=False;initial catalog=student";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Infromation", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("学号", "学号"),
new System.Data.Common.DataColumnMapping("姓名", "姓名"),
new System.Data.Common.DataColumnMapping("性别", "性别"),
new System.Data.Common.DataColumnMapping("年龄", "年龄"),
new System.Data.Common.DataColumnMapping("出生日期", "出生日期"),
new System.Data.Common.DataColumnMapping("家庭住址", "家庭住址"),
new System.Data.Common.DataColumnMapping("系部", "系部"),
new System.Data.Common.DataColumnMapping("班级", "班级")})});
//
// dataGrid1
//
this.dataGrid1.DataMember = "Infromation";
this.dataGrid1.DataSource = this.dataSet11;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(64, 80);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(400, 176);
this.dataGrid1.TabIndex = 0;
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(104, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(272, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 24);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 学号, 姓名, 性别, 年龄, 出生日期, 家庭住址, 系部, 班级 FROM Infromation";
this.sqlSelectCommand1.Connection = this.sqlConnection2;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Infromation(学号, 姓名, 性别, 年龄, 出生日期, 家庭住址, 系部, 班级) VALUES (@学号, @姓名, @性别" +
", @年龄, @出生日期, @家庭住址, @系部, @班级); SELECT 学号, 姓名, 性别, 年龄, 出生日期, 家庭住址, 系部, 班级 FROM I" +
"nfromation";
this.sqlInsertCommand1.Connection = this.sqlConnection2;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学号", System.Data.SqlDbType.VarChar, 10, "学号"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 10, "姓名"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@性别", System.Data.SqlDbType.VarChar, 10, "性别"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年龄", System.Data.SqlDbType.VarChar, 10, "年龄"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@出生日期", System.Data.SqlDbType.DateTime, 8, "出生日期"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@家庭住址", System.Data.SqlDbType.VarChar, 10, "家庭住址"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@系部", System.Data.SqlDbType.VarChar, 50, "系部"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@班级", System.Data.SqlDbType.VarChar, 50, "班级"));
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString = "workstation id=DMT;packet size=4096;user id=sa;data source=dmt;persist security i" +
"nfo=False;initial catalog=student";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(536, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
this.sqlSelectCommand1.CommandText="select * from grxx where 姓名='"+this.textBox1.Text.Trim()+"'";
}

private void Form1_Load(object sender, System.EventArgs e)
{
/*this.sqlDataAdapter1.Fill(this.dataSet1,"Customers");
this.dataGrid1.DataSource=this.dataSet1;
if(!this.dataGrid1.IsExpanded(0))
this.dataGrid1.Expand(0);*/
}


}
}

2006-03-14 22:10
快速回复:关于C#的类!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015874 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved