using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace WindowsApplication24
{
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.DataGrid dataGrid1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBox4;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        /// <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.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.textBox4 = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(8, 8);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.Size = new System.Drawing.Size(488, 200);
            this.dataGrid1.TabIndex = 0;
            this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(8, 272);
            this.button1.Name = "button1";
            this.button1.TabIndex = 1;
            this.button1.Text = "添加";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8, 224);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(80, 23);
            this.label1.TabIndex = 2;
            this.label1.Text = "label1";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(80, 224);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(72, 21);
            this.textBox1.TabIndex = 3;
            this.textBox1.Text = "";
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(248, 224);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(72, 21);
            this.textBox2.TabIndex = 5;
            this.textBox2.Text = "";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(168, 224);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(80, 23);
            this.label2.TabIndex = 4;
            this.label2.Text = "label2";
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(408, 224);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(72, 21);
            this.textBox3.TabIndex = 7;
            this.textBox3.Text = "";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(328, 224);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(80, 23);
            this.label3.TabIndex = 6;
            this.label3.Text = "label3";
            // 
            // textBox4
            // 
            this.textBox4.Location = new System.Drawing.Point(408, 272);
            this.textBox4.Name = "textBox4";
            this.textBox4.Size = new System.Drawing.Size(72, 21);
            this.textBox4.TabIndex = 9;
            this.textBox4.Text = "";
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(328, 272);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(80, 23);
            this.label4.TabIndex = 8;
            this.label4.Text = "label4";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(120, 272);
            this.button2.Name = "button2";
            this.button2.TabIndex = 10;
            this.button2.Text = "button2";
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(232, 272);
            this.button3.Name = "button3";
            this.button3.TabIndex = 11;
            this.button3.Text = "button3";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(512, 318);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.textBox4);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            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();
            this.ResumeLayout(false);
        }
        #endregion
        
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        /// 
        private DataSet ds=new DataSet();
        private SqlConnection conn;
        private SqlDataAdapter da;
        private SqlParameter par=new SqlParameter();
        private DataTable table=new DataTable();
        private CurrencyManager man;
    
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                DataRow row=this.ds.Tables["jobs"].NewRow();
                row["job_id"]=this.textBox1.Text;
                row["job_desc"]=this.textBox2.Text;
                row["min_lvl"]=this.textBox3.Text;
                row["max_lvl"]=this.textBox4.Text;
                this.ds.Tables["jobs"].Rows.Add(row);
                this.ds.HasChanges(DataRowState.Added);
                this.da.Update(this.ds,"jobs");
                MessageBox.Show("添加成功");
                this.textBox1.Clear();
                this.textBox2.Clear();
                this.textBox3.Clear();
                this.textBox4.Clear();
                this.dataGrid1.Update();
                this.textBox1.Focus();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        private void Form1_Load(object sender, System.EventArgs e)
        {
            this.textBox1.Enabled=false;
            conn=new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
            this.da=new SqlDataAdapter("select *from jobs",conn);
            this.da.Fill(this.ds,"jobs");
            this.dataGrid1.DataSource=this.ds;
            this.dataGrid1.DataMember="jobs";
            this.da.Fill(this.table);
            this.dataGrid1.DataSource=this.table.DefaultView;
            this.man=(CurrencyManager)BindingContext[this.table];
            this.dataGrid1.SetDataBinding(this.ds,"jobs");
            string incmd="insert into jobs values(@job_id,@job_desc,@min_lvl,@max_lvl)";
            this.da.InsertCommand=new SqlCommand(incmd,conn);
            this.par=this.da.InsertCommand.Parameters.Add("@job_id",SqlDbType.SmallInt,2);
            this.par.SourceColumn="job_id";
            this.par.SourceVersion=DataRowVersion.Current;
            this.par=this.da.InsertCommand.Parameters.Add("@job_desc",SqlDbType.VarChar,50);
            this.par.SourceColumn="job_desc";
            this.par.SourceVersion=DataRowVersion.Current;
            this.par=this.da.InsertCommand.Parameters.Add("@min_lvl",SqlDbType.TinyInt,1);
            this.par.SourceColumn="min_lvl";
            this.par.SourceVersion=DataRowVersion.Current;
            this.par=this.da.InsertCommand.Parameters.Add("@max_lvl",SqlDbType.TinyInt,1);
            this.par.SourceColumn="max_lvl";
            this.par.SourceVersion=DataRowVersion.Current;
            zq();
        }
        private void zq()
        {
            try
            {
                this.textBox1.DataBindings.Add("Text",this.table,"job_id");
                this.textBox2.DataBindings.Add("Text",this.table,"job_desc");
                this.textBox3.DataBindings.Add("Text",this.table,"min_lvl");
                this.textBox4.DataBindings.Add("Text",this.table,"max_lvl");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
        {
            if(this.table.Rows.Count>0)
            {
                int count=this.dataGrid1.CurrentCell.RowNumber;
                if(count>0&&count<=this.man.Count)
                {
                    this.man.Position=count;
                }
            }
        }
    }
}
问题是我在点添加按鈕是怎么让下面的文本框数据自动清空~~!@@!@

 
											





 
	    
 把文本框里附个空格不就行了?
把文本框里附个空格不就行了?										
					
	




