用DataView进行绑定,然后取消修改后取DataView的所有Row的状态为Orginal的数据

解决方案 »

  1.   

    我是用dataset,datatable的.
        用DataView有點不太習慣, 特別是綁定到datagrid時, 需要用戶輸入完後新增一空白行才可已正確儲存數據. 如果方便請將DataView的實現貼出來看看參考參考。
      

  2.   

    代码如下:
    首先取得数据,放到DataGrid里System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=localhost;database=northWind;uid=sa;password=110");
    conn.Open();
    System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from student",conn);
    dt = new System.Data.DataSet();
    da.Fill(dt,"student");然后绑定数据集和DataGrid
    DataGrid.SetDataBinding(dt,"student");
    如果需要,可以绑定TextBox来作录入,而用DataGrid显示
    this.textBox16.DataBindings.Add("Text",dt,"student.stuno");
    然后进行数据的操作如:
    增加:
    this.BindingContext[dt,"student"].AddNew();
    删除:
    this.BindingContext[dt,"student"].RemoveAt(this.BindingContext[dt,"student"].Position);
    如果在没有调用Update之
    就用this.BindingContext[dt,"student"].CancelCurrentEdit();
    this.dt.RejectChanges();
      

  3.   

    Rossetti:
          不保存當然可以, 但我想不用關閉當前畫面(winform). 
          這樣: 用戶選擇一紀錄後 按[編輯], 在某些textbox上輸入/更改了數據,但發現改錯了, 如是按[cancel], 此時需立即回覆原來的數據, 而不用關閉此winform.