④、刪除DataRow
DataRow rowCustomer;
rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI");
rowCustomer.Delete();
⑤、清除DataRow
DataRow rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI");
rowCustomer.ItemArray = aCustomer;
da.Tables["Customers"].Remove(rowCustomer);
或者
ds.Tables["Customers"].RemoveAt(intIndex);
⑥、使用DataRow.RowState屬性 :Unchanged,Detached,Added,ModifIEd,Deleted
private void DemonstrateRowState()
{ // Run a function to create a DataTable with one column. DataTable myTable = MakeTable();DataRow myRow;
// Create a new DataRow. myRow = myTable.NewRow();// Detached row. Console.WriteLine("New Row " + myRow.RowState);
myTable.Rows.Add(myRow);// New row. Console.WriteLine("AddRow " + myRow.RowState);
myTable.AcceptChanges();// Unchanged row. Console.WriteLine("AcceptChanges " + myRow.RowState);
myRow["FirstName"] = "Scott";// Modified row. Console.WriteLine("ModifIEd " + myRow.RowState);
myRow.Delete();// Deleted row. Console.WriteLine("Deleted " + myRow.RowState);}
⑦、檢查DataRow中的掛起更改
DataRow rowCustomer;
rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI");
rowCustomer["CompanyName"] = "NewCompanyName";
string strNewCompanyName,strOldCompanyName;
Console.WriteLine(rowCustomer["CompanyName",DataRowVersion.Current]);
Console.WriteLine(rowCustomer["CompanyName",DataRowVersion.Original]);
1、DataSet
①、屬性
CaseSensitive:用於控制DataTable中的字符串比較是否區分大小寫。
DataSetName:當前DataSet的名稱。如果不指定,則該屬性值設置為"NewDataSet".如果將DataSet內容寫入XML文件,DataSetName是XML文件的根節點名稱。
DesignMode:如果在設計時使用組件中的DataSet,DesignMode返回True,否則返回False.
HasErrors:表示DataSet中的DataRow對象是否包含錯誤。如果將一批更改提交給數據庫並將DataAdapter對象的ContinueUpdateOnError屬性設置為True,則在提交更改後必須檢查DataSet的HasErrors屬性,以確定是否有更新失敗。
NameSpace和Prefix:指定XML命名空間和前綴
Relations:返回一個DataRelationCollection對象。
Tables:檢查現有的DataTable對象。通過索引訪問DataTable有更好的性能。