2010-03-26 33 views
1

我試試這個DataSet.GetChanges()返回NULL C#

DataSet ds = new DataSet(); 
ds.AcceptChanges(); 

//edit table in ds 
ds.Tables[0].Rows.RemoveAt(0); 

//get changes 
DataSet ds2 = ds.GetChanges(); 

but ds2 is null, why? 

回答

1

也許表已經空了,不除去第一行並沒有改變什麼嗎?

+0

我在網格視圖中綁定數據集表,並且比我稱之爲代碼 – Paul 2010-03-26 16:59:04

1

使用刪除RemoveAt移除,而不是:

//ds.Tables[0].Rows.RemoveAt(0); 
ds.Tables[0].Rows[0].Delete(); 

RemoveAt移除()真的刪除行,沒有它留痕跡,因此沒有變化信息。刪除()只是將該行標記爲已刪除。

+0

非常感謝,它是有用的 – Paul 2010-03-26 18:09:54