我有一表
create table 表(
lsh   int   identity(1,1),
colName     varchar(20),
...
)
我使用查询语句select * from 表 where lsh = 0来查询数据,因为lsh = 0,自然是没有数据了,于是我插入新记录:
rs.AddNew
rs("colName") = "新值"
rs("...") = "..."
rs.updatebatch 当前记录
此时,我想知道新插入的记录的lsh是多少,如何实现,不能重新查询最大值,因为在我插入记录的同时别人也可能插入新记录的。谢谢!

解决方案 »

  1.   

    SELECT @@IDENTITY as lsh
      

  2.   

    不想重新查询,如何能插入的同时返回LSH呢,难道只能用存储过程来实现吗?
    使用SELECT @@IDENTITY as lsh时可能其他人也刚刚插入一条记录,这样返回的LSH就不是刚刚插入的了。
      

  3.   

    create proc insert_表 
    @colName varchar(20),
    ....
    as
    begin
         insert into tablename(colname,.....) 
         values (@colname,....)     SELECT @@IDENTITY as lsh
    end 
      

  4.   

    我不推荐使用 Rs 的 Addnew 方法
      

  5.   

    用存储过程?
    在存储过程中使用INSERT语句,总是没有返回值返回。
      

  6.   

    rs.AddNew
    rs("colName") = "新值"
    rs("...") = "..."
    rs.update
    '如果是 DAO
    'rs.Book = rs.Lastmodified
    msgbox rs!lsh