access中一字段从1开始编码

and 2000-07-12 10:31:00
我用VB (ADO)写一access数据库应用,库中一些表都有一个字段是自动增加型的,由于要经常对这些表进行删除,致使增加记录时,那些自动增加型字段的值不是从1开始。请问在VB中如何使这些字段从1开始?谢谢。
...全文
136 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyang 2000-07-12
  • 打赏
  • 举报
回复
我原来的作法是把字段类型改掉,再改回来。
上面的文档是让and失望一下。除非他用access2000.:>
TopHead 2000-07-12
  • 打赏
  • 举报
回复
上面的文档的目的好像不是and所需要的啊,我原来对付 使这些字段从1重新开始 的方法是在数据库中建立一个新表,然后将数据由原来的表写入新表中,最后将新表的名字改成你想要的,很傻是吧,我觉得也是:)不过我没想到什么别的方法。
liyang 2000-07-12
  • 打赏
  • 举报
回复
看这个:
Setting autoincrement field values

Access 2000 is the first version of Access that lets developers set the start and step value of autoincrement columns. You can programmatically set the start and step value of autoincrement columns by creating the table with Jet 4.0 SQL statements. You use the CREATE TABLE command to create the overall table, and you use the IDENTITY data type in Jet SQL for the autoincrement field. The IDENTITY data type has start and step values that let you specify the initial value for the autoincrement field, as well as how much it increases with each new record. The following SetStartAndStep procedure taps this new technology.

Sub SetStartAndStep()
Dim cnn1 As Connection
Dim cmd1 As Command
Dim tbl1 As New Table

Set cnn1 = CurrentProject.Connection
Set cmd1 = New ADODB.Command

With cmd1
.ActiveConnection = cnn1
'First create a table with two columns.
'Make one column an Identity column.
'Set its start value first, and its step value second.
.CommandType = adCmdText
.CommandText = "CREATE TABLE Contacts (ContactID " & _
"IDENTITY(2,4),ContactName Char)"
.Execute
'After creating the table with the autoincrement/identity
'column, you should add data.
.CommandText = "INSERT INTO Contacts(ContactName) " & _
"Values ('Kevin Mineweaser')"
.CommandType = adCmdText
.Execute
.CommandText = "INSERT INTO Contacts(ContactName) " & _
"Values ('Mike Gilbert')"
.CommandType = adCmdText
.Execute
.CommandText = "INSERT INTO Contacts(ContactName) " & _
"Values ('Neil Charney')"
.CommandType = adCmdText
.Execute
End With

End Sub

liyang 2000-07-12
  • 打赏
  • 举报
回复
好像直接赋值就可以。试试看。
and 2000-07-12
  • 打赏
  • 举报
回复
感谢各位的参与。我用的是access97,直接赋值肯定是不行的。DAO进行PACK也是能行的。我期待的是ADO 的类似方法,现在看来只有采用DAO来PACK 了。
zigzag 2000-07-12
  • 打赏
  • 举报
回复
删空后对数据库进行压缩,处理之后在增加记录,则会从1开始。
我试了(Access2000),很有效。Access97中我想也行。
在vb中可用DAO的DBEngine对象的CompactDatabase方法压缩数据库,好象ADO中没有现成的方法。你可以用ADO存取数据库,用DAO来压缩数据库,两者兼而用之。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧