给个例子
private void DemonstrateDeleteRow(){
// Create a simple DataTable with two columns and ten rows.
DataTable myTable = new DataTable("myTable");
DataColumn c1 = new DataColumn("id",Type.GetType("System.Int32"));
c1.AutoIncrement=true;
DataColumn c2 = new DataColumn("item", Type.GetType("System.String"));
myTable.Columns.Add(c1);
myTable.Columns.Add(c2);
// Add ten rows.
DataRow newRow;
for(int i = 0; i <10; i++){
newRow = myTable.NewRow();
newRow["item"] = "Item " + i;
myTable.Rows.Add(newRow);
}
myTable.AcceptChanges();
// Create a DataView with the table.
DataRowCollection rc = myTable.Rows;
rc[0].Delete();
rc[2].Delete();
rc[3].Delete();
rc[5].Delete();
Console.WriteLine(rc[3].RowState.ToString());
// Reject changes on one deletion.
rc[3].RejectChanges();
// Change the value of the column so it stands out.
rc[3]["item"] = "Deleted, Undeleted, Edited";
// Accept changes on others.
myTable.AcceptChanges();
// Print the remaining row values.
foreach(DataRow r in myTable.Rows){
Console.WriteLine(r[0] + "\t" + r[1]);
}
private void DemonstrateDeleteRow(){
// Create a simple DataTable with two columns and ten rows.
DataTable myTable = new DataTable("myTable");
DataColumn c1 = new DataColumn("id",Type.GetType("System.Int32"));
c1.AutoIncrement=true;
DataColumn c2 = new DataColumn("item", Type.GetType("System.String"));
myTable.Columns.Add(c1);
myTable.Columns.Add(c2);
// Add ten rows.
DataRow newRow;
for(int i = 0; i <10; i++){
newRow = myTable.NewRow();
newRow["item"] = "Item " + i;
myTable.Rows.Add(newRow);
}
myTable.AcceptChanges();
// Create a DataView with the table.
DataRowCollection rc = myTable.Rows;
rc[0].Delete();
rc[2].Delete();
rc[3].Delete();
rc[5].Delete();
Console.WriteLine(rc[3].RowState.ToString());
// Reject changes on one deletion.
rc[3].RejectChanges();
// Change the value of the column so it stands out.
rc[3]["item"] = "Deleted, Undeleted, Edited";
// Accept changes on others.
myTable.AcceptChanges();
// Print the remaining row values.
foreach(DataRow r in myTable.Rows){
Console.WriteLine(r[0] + "\t" + r[1]);
}
如果需要两个字段的值才能找到需要的一行,该怎样作呢?
"int i=dvtable.Find("你知道的值");//最好是主健或unique"
难道是int i=dvtable.Find("你知道的值1",“值2”)?;
试试行不行