②、修改當前行
修改行的內容逼供內不會自動修改數據庫中相應的內容,對行所做的修改被視為是隨後將使用SqlDataAdapter對象來提交交給數據庫的待定的更改。
DataRow rowCustomer;
rowCustomer = ds.Tables["Custoemrs"].Rows.Find("ANTON");
if(rowCustomer == null)
//沒有查找客戶
else
{
rowCustomer["CompanyName"] ="NewCompanyName";
rowCustomer["ContactName"] ="NewContactName";
}
//推薦使用這種方式
DataRow rowCustomer;
rowCustomer = ds.Tables["Custoemrs"].Rows.Find("ANTON");
if(rowCustomer == null)
//沒有查找客戶
else
{
rowCustomer.BeginEdit();
rowCustomer["CompanyName"] ="NewCompanyName";
rowCustomer["ContactName"] ="NewContactName";
rowCustomer.EndEdit();
}
//null表示不修改該列的數據
obejct[] aCustomer ={null,"NewCompanyName","NewContactName",null}
DataRow rowCustomer;
rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI");
rowCustomer.ItemArray = aCustomer;
③、處理DataRow的空值
//查看是否為空
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;