系统中的一个界面里有添加 删除 修改 3个控件 修改信息后当时就可以看到结果但是添加和删除信息后 不能直接看到结果 要关掉界面重新开打后才能看到 结果
在窗口加载的时候,用了一个DATASET  到最后还是用的那个DATASET   需要把DATASET更新一下我现在对哪个东西不是很了解, 请大家有熟悉的朋友帮我写一下代码    再线等

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.SqlClient;namespace Student
    {
    /// <summary>
    /// Specialty 的摘要说明。
    /// </summary>
    public class Specialty : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button bnSearchAll;
    private System.Windows.Forms.Button bnDel;
    private System.Windows.Forms.Button bnAdd;
    private System.Windows.Forms.Button bnSearch;
    private System.Windows.Forms.TextBox tbSpecialtyName;
    private System.Windows.Forms.TextBox tbSpecialtyID;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Button button3;
    private BindingManagerBase myBinding;
    private System.Windows.Forms.Button bnForward;
    private System.Windows.Forms.Button bnBack;
    private System.Windows.Forms.Label lbMessage;
    DataSet ds=new DataSet();
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox tbClassNum;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Specialty()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();
    string sql="select * from specialty";
    ds=DataAccess.GetDataSet(sql,"Specialty");
    tbSpecialtyID.DataBindings.Add("Text",ds,"Specialty.SpecialtyID");
    tbSpecialtyName.DataBindings.Add("Text",ds,"Specialty.SpecialtyName");
    tbClassNum.DataBindings.Add("Text",ds,"Specialty.ClassNum");
    this.myBinding=this.BindingContext[ds,"Specialty"];
    lbMessage.Text="当前第"+(myBinding.Position+1)+"/"+myBinding.Count+"条记录"; //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
      

  2.   

    http://blog.csdn.net/laily/archive/2004/06/24/25872.aspx 经典正则表达式
      

  3.   

    #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.bnSearchAll = new System.Windows.Forms.Button();
    this.bnDel = new System.Windows.Forms.Button();
    this.bnAdd = new System.Windows.Forms.Button();
    this.bnSearch = new System.Windows.Forms.Button();
    this.tbSpecialtyName = new System.Windows.Forms.TextBox();
    this.tbSpecialtyID = new System.Windows.Forms.TextBox();
    this.label2 = new System.Windows.Forms.Label();
    this.label1 = new System.Windows.Forms.Label();
    this.groupBox1 = new System.Windows.Forms.GroupBox();
    this.tbClassNum = new System.Windows.Forms.TextBox();
    this.label3 = new System.Windows.Forms.Label();
    this.button3 = new System.Windows.Forms.Button();
    this.lbMessage = new System.Windows.Forms.Label();
    this.bnForward = new System.Windows.Forms.Button();
    this.bnBack = new System.Windows.Forms.Button();
    this.groupBox1.SuspendLayout();
    this.SuspendLayout();
    // 
    // bnSearchAll
    // 
    this.bnSearchAll.Location = new System.Drawing.Point(401, 225);
    this.bnSearchAll.Name = "bnSearchAll";
    this.bnSearchAll.TabIndex = 23;
    this.bnSearchAll.Text = "查询所有";
    this.bnSearchAll.Click += new System.EventHandler(this.bnSearchAll_Click);
    // 
    // bnDel
    // 
    this.bnDel.Location = new System.Drawing.Point(313, 225);
    this.bnDel.Name = "bnDel";
    this.bnDel.TabIndex = 22;
    this.bnDel.Text = "删除";
    this.bnDel.Click += new System.EventHandler(this.bnDel_Click);
    // 
    // bnAdd
    // 
    this.bnAdd.Location = new System.Drawing.Point(129, 225);
    this.bnAdd.Name = "bnAdd";
    this.bnAdd.TabIndex = 21;
    this.bnAdd.Text = "添加";
    this.bnAdd.Click += new System.EventHandler(this.bnAdd_Click);
    // 
    // bnSearch
    // 
    this.bnSearch.Location = new System.Drawing.Point(41, 225);
    this.bnSearch.Name = "bnSearch";
    this.bnSearch.TabIndex = 20;
    this.bnSearch.Text = "查询";
    this.bnSearch.Click += new System.EventHandler(this.bnSearch_Click);
    // 
    // tbSpecialtyName
    // 
    this.tbSpecialtyName.Location = new System.Drawing.Point(209, 137);
    this.tbSpecialtyName.Name = "tbSpecialtyName";
    this.tbSpecialtyName.Size = new System.Drawing.Size(128, 21);
    this.tbSpecialtyName.TabIndex = 18;
    this.tbSpecialtyName.Text = "";
    // 
    // tbSpecialtyID
    // 
    this.tbSpecialtyID.Location = new System.Drawing.Point(209, 97);
    this.tbSpecialtyID.Name = "tbSpecialtyID";
    this.tbSpecialtyID.Size = new System.Drawing.Size(128, 21);
    this.tbSpecialtyID.TabIndex = 17;
    this.tbSpecialtyID.Text = "";
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(97, 137);
    this.label2.Name = "label2";
    this.label2.TabIndex = 15;
    this.label2.Text = "专业名:";
    this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(96, 96);
    this.label1.Name = "label1";
    this.label1.TabIndex = 14;
    this.label1.Text = "专业号:";
    this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // groupBox1
    // 
    this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
    this.tbClassNum,
    this.label3,
    this.button3,
    this.lbMessage,
    this.bnForward,
    this.bnBack});
    this.groupBox1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
    this.groupBox1.Location = new System.Drawing.Point(17, 33);
    this.groupBox1.Name = "groupBox1";
    this.groupBox1.Size = new System.Drawing.Size(488, 280);
    this.groupBox1.TabIndex = 24;
    this.groupBox1.TabStop = false;
    this.groupBox1.Text = "专业设置";
    // 
    // tbClassNum
    // 
    this.tbClassNum.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
    this.tbClassNum.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
    this.tbClassNum.Location = new System.Drawing.Point(192, 152);
    this.tbClassNum.Name = "tbClassNum";
    this.tbClassNum.ReadOnly = true;
    this.tbClassNum.Size = new System.Drawing.Size(48, 21);
    this.tbClassNum.TabIndex = 5;
    this.tbClassNum.Text = "";
    // 
    // label3
    // 
    this.label3.Location = new System.Drawing.Point(72, 152);
    this.label3.Name = "label3";
    this.label3.TabIndex = 4;
    this.label3.Text = "班级数目:";
    this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // button3
    // 
    this.button3.Location = new System.Drawing.Point(200, 192);
    this.button3.Name = "button3";
    this.button3.TabIndex = 3;
    this.button3.Text = "修改";
    // 
    // lbMessage
    // 
    this.lbMessage.Location = new System.Drawing.Point(176, 232);
    this.lbMessage.Name = "lbMessage";
    this.lbMessage.Size = new System.Drawing.Size(160, 23);
    this.lbMessage.TabIndex = 2;
    this.lbMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // bnForward
    // 
    this.bnForward.Location = new System.Drawing.Point(352, 232);
    this.bnForward.Name = "bnForward";
    this.bnForward.TabIndex = 1;
    this.bnForward.Text = ">";
    this.bnForward.Click += new System.EventHandler(this.bnForward_Click);
    // 
    // bnBack
    // 
    this.bnBack.Location = new System.Drawing.Point(72, 232);
    this.bnBack.Name = "bnBack";
    this.bnBack.TabIndex = 0;
    this.bnBack.Text = "<";
    this.bnBack.Click += new System.EventHandler(this.button1_Click);
    // 
    // Specialty
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.BackColor = System.Drawing.Color.LightSteelBlue;
    this.ClientSize = new System.Drawing.Size(522, 346);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      

  4.   

    this.bnSearchAll,
      this.bnDel,
      this.bnAdd,
      this.bnSearch,
      this.tbSpecialtyName,
      this.tbSpecialtyID,
      this.label2,
      this.label1,
      this.groupBox1});
    this.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
    this.Name = "Specialty";
    this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
    this.Text = "专业设置";
    this.groupBox1.ResumeLayout(false);
    this.ResumeLayout(false); }
    #endregion private void button1_Click(object sender, System.EventArgs e)
    {
    bnForward.Enabled=true;
    if(myBinding.Position==0)
    bnBack.Enabled=false;
    else
    {
    myBinding.Position--;
    lbMessage.Text="当前第"+(myBinding.Position+1)+"/"+myBinding.Count+"条记录";
    } } private void bnForward_Click(object sender, System.EventArgs e)
    {
    bnBack.Enabled=true;
    if(myBinding.Position==myBinding.Count-1)
    bnForward.Enabled=false;
    else
    {
    myBinding.Position++;
    lbMessage.Text="当前第"+(myBinding.Position+1)+"/"+myBinding.Count+"条记录";
    }
    } private void bnSearch_Click(object sender, System.EventArgs e)
    {
    if(tbSpecialtyID.Text!="")
    {
    string sql="select * from specialty where specialtyID="+tbSpecialtyID.Text;
    SqlDataReader dr=DataAccess.GetReader(sql);
    if(dr.Read())
    {
    tbSpecialtyName.Text=dr.GetString(1);
    dr.Close();
    }
    else
    MessageBox.Show("无此记录");
    }
    else
    MessageBox.Show("请输入专业号进行查询");
    } private void bnAdd_Click(object sender, System.EventArgs e)
    {
    if(tbSpecialtyID.Text!=""&&tbSpecialtyName.Text!="")
    {
    string strSql="Insert into Specialty(SpecialtyID,SpecialtyName,Classnum) values ("+int.Parse(tbSpecialtyID.Text)+",'"+tbSpecialtyName.Text+"',0)";
    if(DataAccess.ExecuteSQL(strSql))
    MessageBox.Show("插入成功");
    else MessageBox.Show("插入失败");
    }
    else
    MessageBox.Show("专业号或专业名不能为空!");
    } private void bnSearchAll_Click(object sender, System.EventArgs e)
    {
    DataSet ds=new DataSet();
    string sql="select specialtyid 专业号,specialtyname 专业名,classnum 班级数 from specialty";
    ds=DataAccess.GetDataSet(sql,"Specialty");
    new ShowAll(ds,"Specialty").Show();
    } private void bnDel_Click(object sender, System.EventArgs e)
    {
    if(tbSpecialtyID.Text!="")
    {
    string strSql="delete from  Specialty where specialtyid="+int.Parse(tbSpecialtyID.Text);
    if(MessageBox.Show("此动作会丢失所有与此系有关的班级、学生信息,您真的要删除吗?","温馨提示",MessageBoxButtons.YesNo,MessageBoxIcon.Asterisk)==DialogResult.Yes)
    {
    if(DataAccess.ExecuteSQL(strSql))
    MessageBox.Show("删除成功");
    else MessageBox.Show("删除失败");
    }
    }
    else
    MessageBox.Show("专业号不能为空!");
    }
    }
    }
      

  5.   

    修改按钮的操作怎么没有?我大体明白你的意思了,其实你这里边不是有个查询所有的按钮吗?你可以把查询所有按钮里边的内容放到一个函数或者过程中,在你做完删除后调用一下该函数不就行了其实解决的方法是很多的
    你说的更新dataset,怎么更新了?重新取一次不就更新了?
      

  6.   

    具体的代码不清楚怎么改不过在删除和插入时可以调用PAGE_LOAD的方法重新获取数据再重新绑定就可以了
      

  7.   

    我饿了,先改一个你试试
    private void bnSearchAll_Click(object sender, System.EventArgs e)
    {setDataSourse();
    }
    private void setDataSourse()
    {
    DataSet ds=new DataSet();
    string sql="select specialtyid 专业号,specialtyname 专业名,classnum 班级数 from specialty";
    ds=DataAccess.GetDataSet(sql,"Specialty");
    new ShowAll(ds,"Specialty").Show();}在你的添加完成后边调用setDataSourse()看看,我这只是说说思路,可能有问题,你自己改改,回家吃饭了