还是一道数据库题:(

viky_yuhongjun 2002-02-20 08:41:29
下面这段程序是想向SQL数据库中的student表中插入10个连续整数,可运行时出错:“不能在对象'student'中插入重复键“,请教大侠小弟的程序哪里出了差错?百思不得其解!
Dim id
id = Text1.Text

With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "insert into student(number)values(" + id + ")"
End With

For i = 1 To 10
cmd.Execute
id = id + 1
Next i
...全文
5 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
viky_yuhongjun 2002-02-20
number是bigint类型的
回复
40Star 2002-02-20
哪你的number字段是?类型
回复
viky_yuhongjun 2002-02-20
可这次它说:“类型不匹配“错在:.CommandText = "insert into student(number)values(" + id + ")" 行
回复
dbcontrols 2002-02-20
For i = 1 To 10
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "insert into student(number)values(" & id & ")"
End With
cmd.Execute
id = id + 1
Next i
回复
40Star 2002-02-20
For i = 1 To 10
With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "insert into student(number)values(" + id + ")"
End With
cmd.Execute
id = id + 1
Next i
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告