vb 向数据库添加数据的问题
PrivateSubCommand1_Click()IfText1.Text=""OrText2.Text=""OrText3.Text=""OrText4.Text="...
Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
If Trim(Text1.Text) = "" Then
MsgBox "请输入编号"
Text1.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(Text1.Text)) Then
MsgBox "编号必须是数字"
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "请输入姓名"
Text2.SetFocus
Exit Sub
End If
If Trim(Text3.Text) = "" Then
MsgBox "请输入病症"
Text3.SetFocus
Exit Sub
End If
If Trim(Text4.Text) = "" Then
MsgBox "请输入价格"
Text4.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "编号必须是数字"
Text4.SetFocus
Exit Sub
End If
If Trim(Adodc1.Recordset.Fields("cno")) = Trim(Text1.Text) Then
MsgBox "此编号已存在,请重新输入"
Text1.SetFocus
Exit Sub
End If
If Trim(Text5.Text) = "" Then
MsgBox "请输入药品"
Text5.SetFocus
Exit Sub
End If
Else
On Error Resume Next
Adodc1.Recordset.MoveNext
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc1.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc1.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc1.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc1.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc1.Recordset.Fields("sname") = Trim(Combo2.Text)
Adodc2.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc2.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc2.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc2.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc2.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc2.Recordset.Fields("dname") = Trim(Combo3.Text)
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Adodc2.Recordset.Update
Adodc2.Recordset.Close
Adodc1.Refresh
Adodc2.Refresh
MsgBox "插入成功"
End If
End Sub
这段代码错误重重。。但我实在不会改了。。求各位帮忙了。。附上数据库数据
。。帮忙改下吧。。我会追加的分数的
我就是想在text为空时会提示。。当都输入时在执行添加操作。。但是总感觉我这方式是错的。。就是刚开始那if语句。。 展开
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
If Trim(Text1.Text) = "" Then
MsgBox "请输入编号"
Text1.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(Text1.Text)) Then
MsgBox "编号必须是数字"
Text1.SetFocus
Exit Sub
End If
If Trim(Text2.Text) = "" Then
MsgBox "请输入姓名"
Text2.SetFocus
Exit Sub
End If
If Trim(Text3.Text) = "" Then
MsgBox "请输入病症"
Text3.SetFocus
Exit Sub
End If
If Trim(Text4.Text) = "" Then
MsgBox "请输入价格"
Text4.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(Text4.Text)) Then
MsgBox "编号必须是数字"
Text4.SetFocus
Exit Sub
End If
If Trim(Adodc1.Recordset.Fields("cno")) = Trim(Text1.Text) Then
MsgBox "此编号已存在,请重新输入"
Text1.SetFocus
Exit Sub
End If
If Trim(Text5.Text) = "" Then
MsgBox "请输入药品"
Text5.SetFocus
Exit Sub
End If
Else
On Error Resume Next
Adodc1.Recordset.MoveNext
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc1.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc1.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc1.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc1.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc1.Recordset.Fields("sname") = Trim(Combo2.Text)
Adodc2.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc2.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc2.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc2.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc2.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc2.Recordset.Fields("dname") = Trim(Combo3.Text)
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Adodc2.Recordset.Update
Adodc2.Recordset.Close
Adodc1.Refresh
Adodc2.Refresh
MsgBox "插入成功"
End If
End Sub
这段代码错误重重。。但我实在不会改了。。求各位帮忙了。。附上数据库数据
。。帮忙改下吧。。我会追加的分数的
我就是想在text为空时会提示。。当都输入时在执行添加操作。。但是总感觉我这方式是错的。。就是刚开始那if语句。。 展开
2个回答
展开全部
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc1.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc1.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc1.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc1.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc1.Recordset.Fields("sname") = Trim(Combo2.Text)
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc2.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc2.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc2.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc2.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc2.Recordset.Fields("dname") = Trim(Combo3.Text)
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Adodc2.Recordset.Update
Adodc2.Recordset.Close
Adodc1.Refresh
Adodc2.Refresh
MsgBox "插入成功"
你最好把出错的语句说出来,这样有针对性的修改
Adodc1.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc1.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc1.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc1.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc1.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc1.Recordset.Fields("sname") = Trim(Combo2.Text)
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc2.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc2.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc2.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc2.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc2.Recordset.Fields("dname") = Trim(Combo3.Text)
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Adodc2.Recordset.Update
Adodc2.Recordset.Close
Adodc1.Refresh
Adodc2.Refresh
MsgBox "插入成功"
你最好把出错的语句说出来,这样有针对性的修改
展开全部
Adodc1.Recordset.MoveNext
Adodc1.Recordset.AddNew
Adodc2.Recordset.AddNew '少了这一句
Adodc1.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc1.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc1.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc1.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc1.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc1.Recordset.Fields("sname") = Trim(Combo2.Text)
Adodc2.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc2.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc2.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc2.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc2.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc2.Recordset.Fields("dname") = Trim(Combo3.Text)
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Adodc2.Recordset.Update
Adodc2.Recordset.Close
Adodc1.Refresh
Adodc2.Refresh
Adodc1.Recordset.AddNew
Adodc2.Recordset.AddNew '少了这一句
Adodc1.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc1.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc1.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc1.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc1.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc1.Recordset.Fields("sname") = Trim(Combo2.Text)
Adodc2.Recordset.Fields("cno") = Trim(Text1.Text)
Adodc2.Recordset.Fields("pname") = Trim(Text2.Text)
Adodc2.Recordset.Fields("csex") = Trim(Combo1.Text)
Adodc2.Recordset.Fields("ill") = Trim(Text3.Text)
Adodc2.Recordset.Fields("wprice") = Trim(Text4.Text)
Adodc2.Recordset.Fields("dname") = Trim(Combo3.Text)
Adodc1.Recordset.Update
Adodc1.Recordset.Close
Adodc2.Recordset.Update
Adodc2.Recordset.Close
Adodc1.Refresh
Adodc2.Refresh
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询