WEB开发网
开发学院软件开发C语言 C# DataSet和DataTable详解 阅读

C# DataSet和DataTable详解

 2009-04-21 08:26:15 来源:WEB开发网   
核心提示: //查看是否为空 DataRow rowCustomer; rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI"); if(rowCustomer.IsNull("Phone"

//查看是否为空

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);}

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:DataSet DataTable 详解

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接