Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1799441
  • 博文数量: 787
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5015
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-22 15:17
文章分类

全部博文(787)

文章存档

2008年(787)

我的朋友

分类:

2008-09-25 16:10:46

 [@more@]

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

namespace WindowsApplication3
{
 ///


 /// Form1 的摘要说明。
 ///

 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.DataGrid dataGrid1;
  private System.Windows.Forms.Splitter splitter1;
  ///
  /// 必需的设计器变量。
  ///

  private System.ComponentModel.Container components = null;

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

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

  ///


  /// 清理所有正在使用的资源。
  ///

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  ///


  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  ///

  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.dataGrid1 = new System.Windows.Forms.DataGrid();
   this.splitter1 = new System.Windows.Forms.Splitter();
   ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Dock = System.Windows.Forms.DockStyle.Top;
   this.button1.Location = new System.Drawing.Point(0, 0);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(400, 23);
   this.button1.TabIndex = 0;
   this.button1.Text = "显示数据";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // dataGrid1
   //
   this.dataGrid1.DataMember = "";
   this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
   this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
   this.dataGrid1.Location = new System.Drawing.Point(0, 23);
   this.dataGrid1.Name = "dataGrid1";
   this.dataGrid1.Size = new System.Drawing.Size(400, 295);
   this.dataGrid1.TabIndex = 1;
   //
   // splitter1
   //
   this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
   this.splitter1.Location = new System.Drawing.Point(0, 23);
   this.splitter1.Name = "splitter1";
   this.splitter1.Size = new System.Drawing.Size(400, 3);
   this.splitter1.TabIndex = 2;
   this.splitter1.TabStop = false;
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(400, 318);
   this.Controls.Add(this.splitter1);
   this.Controls.Add(this.dataGrid1);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Form1";
   ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
   this.ResumeLayout(false);

  }
  #endregion

  ///


  /// 应用程序的主入口点。
  ///

  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }
       
  //按钮事件
  private void button1_Click(object sender, System.EventArgs e)
  {
   //定义数据库连接字符
   string cnStr="Password=123456;Persist Security Info=False;User ID=sa;Initial Catalog=DBOA;Data Source=YORK";
   //创建连接对象
   SqlConnection cn=new SqlConnection(cnStr);
   //定义SQL语句
   string sqlStr="select * from t_cardcontent7";
   //创建适配器对象
   SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlStr,cn);
   //创建数据集对象
   DataSet ds = new DataSet();
   //填充数据集
   myDataAdapter.Fill(ds,"t_cardcontent7");
   //将数据集绑定到DataGrid控件
   dataGrid1.SetDataBinding(ds,"t_cardcontent7");

  }
 }
}



--------------------next---------------------

阅读(551) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~