This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 有个ACCESS的问题请教大家, 一个table是有autonumber的一个字段, 我用insert into语句插入一个数据之后, 想把新生成的autonumber取回来, 可是access好像不支持那个select @@IDENTITY 并不报错, 只说回值为零, 请教各位大侠。
-ningxin0809(雁影行洲);
2005-8-25
(#2469763@0)
-
select max(myautoid)..where myautoid is th field name containing the autonumber. Select @@.. is for SQL server.
-schen(睹往睹来);
2005-8-25
{89}
(#2470544@0)
-
多谢,但是这样的方法是不安全的。 我查了一下,好像在DAO里是用rst.Addnew, 然后拿到新生的ID id=rst("autonumberfiled") 然后把值赴到rst不同字段里, 再用rst.update.
-ningxin0809(雁影行洲);
2005-8-25
(#2470550@0)
-
sorry I thought it's just for a single user..
-schen(睹往睹来);
2005-8-25
(#2470644@0)
-
Then I suggest not to use the autonumber. We usually have an ID control table...before you insert any record, you fetch the ID from the control table and update the control table field by ID+1(or any increment)....
Hope that helps
-schen(睹往睹来);
2005-8-25
{153}
(#2470653@0)
-
thanks, for Access, if use DAO, the way I described aboved works well.
-ningxin0809(雁影行洲);
2005-8-25
(#2470931@0)
-
1. Nothing is updated before rst.update. Try to retrieve new autoid after rst.update. 2. Use DMAX() function to find the highest auto id is better than SQL
-23456789(大白呼);
2005-8-26
(#2472317@0)
-
就是这么做的, 后来才发现是access的传统作法。
-ningxin0809(雁影行洲);
2005-8-26
(#2472326@0)
-
The statement select @@IDENTITY works, I always use this method, but you have to use the same connection as the INSERT command.
-estelle2828(jiakang);
2005-8-25
(#2470693@0)
-
I used the syntax right after insert and it didn;t work. . Are you using DAO or ADO?
-ningxin0809(雁影行洲);
2005-8-25
(#2470934@0)
-
ADO.Net, I guess it's same in ADO, but never tried. In ADO, we use recordset.update.
-estelle2828(jiakang);
2005-8-25
(#2471118@0)
-
如果是ado的话就不一样了, DAO有些东西比较原始
-ningxin0809(雁影行洲);
2005-8-26
(#2472332@0)