上次在数据库的那个版块去问了的。还是没解决这次到基础区来问下
大家看下面我写的代码
我点击添加后直接就执行on error了总是点击第一下不能成功添加到数据库中要点击第二次后才能加到数据库中(但是还是要弹出“主索引不能为重复”这几个字)。我建的主索引是学号但是我输入的值,主索引text4不是重复的,它也执行on error语句我这个到底是哪错了?Private Sub add_Click()
On Error GoTo errorinformation:
If Text4.Text <> "" Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("姓名") = Trim(Text1.Text)
Adodc1.Recordset.Fields("年龄") = Val(Text2.Text)
Adodc1.Recordset.Fields("性别") = Trim(Text3.Text)
Adodc1.Recordset.Fields("学号") = Val(Text4.Text)
Adodc1.Recordset.Fields("语文") = Val(Text5.Text)
Adodc1.Recordset.Fields("数学") = Val(Text6.Text)
Adodc1.Recordset.Fields("外语") = Val(Text7.Text)
Adodc1.Recordset.Fields("专业") = Val(Text8.Text)
Adodc1.Recordset.Fields("总分") = Val(Text9.Text)
Adodc1.Recordset.Update
Adodc1.RecordSource = "select * from cjqk"
Adodc1.Refresh
Do While Not Adodc1.Recordset.EOF
Text4.AddItem Adodc1.Recordset.Fields(1)
Adodc1.Recordset.MoveNext
Loop
Else
MsgBox "为空", 48, "错误提示"
End If
Exit Sub
errorinformation: MsgBox "主索引不能重复", 48 + 0, "提示"
End Sub
大家看下面我写的代码
我点击添加后直接就执行on error了总是点击第一下不能成功添加到数据库中要点击第二次后才能加到数据库中(但是还是要弹出“主索引不能为重复”这几个字)。我建的主索引是学号但是我输入的值,主索引text4不是重复的,它也执行on error语句我这个到底是哪错了?Private Sub add_Click()
On Error GoTo errorinformation:
If Text4.Text <> "" Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("姓名") = Trim(Text1.Text)
Adodc1.Recordset.Fields("年龄") = Val(Text2.Text)
Adodc1.Recordset.Fields("性别") = Trim(Text3.Text)
Adodc1.Recordset.Fields("学号") = Val(Text4.Text)
Adodc1.Recordset.Fields("语文") = Val(Text5.Text)
Adodc1.Recordset.Fields("数学") = Val(Text6.Text)
Adodc1.Recordset.Fields("外语") = Val(Text7.Text)
Adodc1.Recordset.Fields("专业") = Val(Text8.Text)
Adodc1.Recordset.Fields("总分") = Val(Text9.Text)
Adodc1.Recordset.Update
Adodc1.RecordSource = "select * from cjqk"
Adodc1.Refresh
Do While Not Adodc1.Recordset.EOF
Text4.AddItem Adodc1.Recordset.Fields(1)
Adodc1.Recordset.MoveNext
Loop
Else
MsgBox "为空", 48, "错误提示"
End If
Exit Sub
errorinformation: MsgBox "主索引不能重复", 48 + 0, "提示"
End Sub
解决方案 »
- 关于permission denied(许可被拒绝)
- winsock如何登录一个网站?
- VB mscomm 控件 所收到的串口数据处理
- 好苦 救命
- 我用水晶报表8,为什么做成安装程序后,在98下安装以后,使用打印时会报错?
- 小数点“.”的键盘值是多少呀?在线等待。
- 【分享】让你的桌面背景每天自动更新高清高质量的壁纸(from bing)
- 怎么样给回复的人分数啊
- 我有一个查询窗口,我想让它总登陆在当前活动控件的下面,却总是不行,帮我看一下这段代码有什么问题?
- 100分的问题,快来拿啊!(不够再加!)
- 请教如何用 VB实现 检测关机动作并 msgbox "closeing.."
- 请推荐vb操作excel的书籍
if 存在 then
Adodc1.Recordset.AddNew
else
Adodc1.Recordset.EditMode
end if
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("姓名") = Trim(Text1.Text)
Adodc1.Recordset.Fields("年龄") = Val(Text2.Text)
Adodc1.Recordset.Fields("性别") = Trim(Text3.Text)
Adodc1.Recordset.Fields("学号") = Val(Text4.Text)
Adodc1.Recordset.Fields("语文") = Val(Text5.Text)
Adodc1.Recordset.Fields("数学") = Val(Text6.Text)
Adodc1.Recordset.Fields("外语") = Val(Text7.Text)
Adodc1.Recordset.Fields("专业") = Val(Text8.Text)
Adodc1.Recordset.Fields("总分") = Val(Text9.Text)
Adodc1.Recordset.Update
else
Adodc1.Recordset.EditMode
Adodc1.Recordset.Fields("姓名") = Trim(Text1.Text)
Adodc1.Recordset.Fields("年龄") = Val(Text2.Text)
Adodc1.Recordset.Fields("性别") = Trim(Text3.Text)
Adodc1.Recordset.Fields("语文") = Val(Text5.Text)
Adodc1.Recordset.Fields("数学") = Val(Text6.Text)
Adodc1.Recordset.Fields("外语") = Val(Text7.Text)
Adodc1.Recordset.Fields("专业") = Val(Text8.Text)
Adodc1.Recordset.Fields("总分") = Val(Text9.Text)
Adodc1.Recordset.Update
end if