ADO.NET最佳实践(下)[8]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 spidertan 的 blog

  addhandler custda.rowupdated, new sqlrowupdatedeventhandler(addressof onrowupdated)

  dim custds as dataset = new dataset()

  custda.fill(custds, "customers")

  ' modify the dataset contents.

  custda.update(custds, "customers")

  dim myrow as datarow

  for each myrow in custds.tables("customers").rows

    if myrow.haserrors then console.writeline(myrow(0) & vbcrlf & myrow.rowerror)

  next

private shared sub onrowupdated(sender as object, args as sqlrowupdatedeventargs)

  if args.recordsaffected = 0

    args.row.rowerror = "optimistic concurrency violation encountered"

    args.status = updatestatus.skipcurrentrow

  end if

end sub

‘c#

  sqlconnection nwindconn = new sqlconnection("data source=localhost;integrated security=sspi;initial catalog=northwind");

  sqldataadapter custda = new sqldataadapter("select customerid, companyname from customers order by customerid", nwindconn);

  // the update command checks for optimistic concurrency violations in the where clause.

本文关键:数据库设计
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top