C# DataSet和DataTable详解

     添加新DataRow

  DataRow row = ds.Tables["Customers"].NewRow();

  row["CustomerID"] = "ALFKI";

  ds.Tables["Customers"].Rows.Add(row);

  object[] aValues ={"ALFKI","Alfreds","Anders","030-22222"};

  da.Tables["Customers"].LoadDataRow(aValues,false);

     删除DataRow

  DataRow rowCustomer;

  rowCustomer = ds.Tables["Customers"].Rows.Find("ALFKI");

  rowCustomer.Delete();

    修改当前行

  修改行的内容逼供内不会自动修改数据库中相应的内容,对行所做的修改被视为是随后将使用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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值