how are you updating the database? dataset or parameterized query? you can always add a "SELECT @@IDENITY as ID" or "SELECT SCOPE_IDENTITY() AS ID" to retrieve the id
how complicated is your dataset? does it have multiple tables and parent-child relationship? if it is not very complicated, on the client side, use AutoIncrementSeed = -1 and AutoIncrementStep = -1, and only send the Changed DataSet to the webserive. On the server side, use a similar method to what was outlined in the above link to retrieve the new IDs. Then on the client side, delete all records all ID < 0, and merge the returned records, then call AcceptChanges() on the datasetotherwise, you have to requery the database and get all the data again
谢谢 saucer(思归, MS .NET MVP) 老大on the client side, use AutoIncrementSeed = -1 and AutoIncrementStep = -1,delete all records all ID < 0,and merge the returned records ------------------------------------ 这个办法试下先...
或
select max(id) as id from tablename
[WebMethod]
public DataSet UpdateDepartment(DataSet ds){....}客户端更新代码(简):
DataSet changes=dsDepartment.GetChanges();
s.UpdateDepartment(changes);//S为实例化WebService的类
.........//后面应该如何处理才能让本地dsDepartment表中ID更新?【问题】此时DsDepartment.Tables[0]中的ID列如何也同时更新(数据集中仅一个表)?
http://expert.csdn.net/Expert/topic/1528/1528367.xml?temp=.9534723
我是通过GetDataSetChanges()的数据集更新数据,不是用存储过程。为WebService的DataAdapter上添加RowUpdated处理事件,不知为何却返回不了@@identity!?
(按照ms-help://MS.VSCC/MS.MSDNVS.2052/cpguide/html/cpconretrievingidentityorautonumbervalues.htm中的做法,如果直接调用的话没有问题,可放在中间层就不行了)再有,若在WebService中的Changes数据集和数据源保持一致了,那客户端的ID又如何与Changes中的ID保持一致呢?在WebService中可以通过DataAdapter事件(如RowUpdated事件)或命令(SqlCommand),可是客户端因为调用的是WebMethod,如何使ID和WebService中的数据保持一致呢???
------------------------------------
这个办法试下先...