C# DataSet和DataTable详解
2009-04-21 08:26:15 来源:WEB开发网//查看是否为空
DataRow rowCustomer;
rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI");
if(rowCustomer.IsNull("Phone"))
Console.WriteLine("It's Null");
else
Console.WriteLine("It's not Null");
//赋予空值
rowCustomer["Phone"] = DBNull.Value;
④、删除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);}
更多精彩
赞助商链接