关于VB中If Else嵌套语句
IfTrim(txtUserName.Text)<>""AndTrim(txtPassWord.Text)<>""AndTrim(txtPassWord2.Text)<>...
If Trim(txtUserName.Text) <> "" And Trim(txtPassWord.Text) <> "" And Trim(txtPassWord2.Text) <> "" Then
If ComboListRights.Text = ComboListRights.List(0)
Adodc1.RecordSource = "select * from Admin where username='" & Trim(txtUserName.Text) & " '"
Adodc1.Refresh
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc1.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc1.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc1.Recordset.Update
Adodc1.Refresh
FrmUserManage.Adodc1.Recordset.Update
FrmUserManage.Adodc1.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
ElseIf
Adodc2.Recordset.EOF
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc2.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc2.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc2.Recordset.Update
Adodc2.Refresh
FrmUserManage.Adodc2.Recordset.Update
FrmUserManage.Adodc2.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
End If
我做的是试卷自动生成系统里的添加用户页面,因为有两个角色,教师和管理员,所以添加的时候要根据Combolist选择来添加,我就在页面上设了两个Adodc控件来连接数据库中的两张表Teachers和Admin,但是我不会嵌套语句,不知道该怎么设,在Combolist控件(控件名ComboListRights)里选择管理员的时候添加到Adodc1,选择教师的时候添加到Adodc2 展开
If ComboListRights.Text = ComboListRights.List(0)
Adodc1.RecordSource = "select * from Admin where username='" & Trim(txtUserName.Text) & " '"
Adodc1.Refresh
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc1.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc1.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc1.Recordset.Update
Adodc1.Refresh
FrmUserManage.Adodc1.Recordset.Update
FrmUserManage.Adodc1.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
ElseIf
Adodc2.Recordset.EOF
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc2.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc2.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc2.Recordset.Update
Adodc2.Refresh
FrmUserManage.Adodc2.Recordset.Update
FrmUserManage.Adodc2.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
End If
我做的是试卷自动生成系统里的添加用户页面,因为有两个角色,教师和管理员,所以添加的时候要根据Combolist选择来添加,我就在页面上设了两个Adodc控件来连接数据库中的两张表Teachers和Admin,但是我不会嵌套语句,不知道该怎么设,在Combolist控件(控件名ComboListRights)里选择管理员的时候添加到Adodc1,选择教师的时候添加到Adodc2 展开
1个回答
展开全部
If ComboListRights.Text = ComboListRights.List(0)
↑↑↑↑↑
上面这句少了then
根据你的代码修改如下:
If Trim(txtUserName.Text) <> "" And Trim(txtPassWord.Text) <> "" And Trim(txtPassWord2.Text) <> "" Then
If ComboListRights.Text = ComboListRights.List(0) Then
Adodc1.RecordSource = "select * from Admin where username='" & Trim(txtUserName.Text) & " '"
Adodc1.Refresh
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc1.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc1.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc1.Recordset.Update
Adodc1.Refresh
FrmUserManage.Adodc1.Recordset.Update
FrmUserManage.Adodc1.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
Else
If Adodc2.Recordset.EOF Then
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc2.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc2.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc2.Recordset.Update
Adodc2.Refresh
FrmUserManage.Adodc2.Recordset.Update
FrmUserManage.Adodc2.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
End If
End If
+++++++++++++++++++++++++++
by the way 你写的真罗嗦
↑↑↑↑↑
上面这句少了then
根据你的代码修改如下:
If Trim(txtUserName.Text) <> "" And Trim(txtPassWord.Text) <> "" And Trim(txtPassWord2.Text) <> "" Then
If ComboListRights.Text = ComboListRights.List(0) Then
Adodc1.RecordSource = "select * from Admin where username='" & Trim(txtUserName.Text) & " '"
Adodc1.Refresh
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc1.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc1.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc1.Recordset.Update
Adodc1.Refresh
FrmUserManage.Adodc1.Recordset.Update
FrmUserManage.Adodc1.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
Else
If Adodc2.Recordset.EOF Then
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Trim(txtUserName.Text)
Adodc2.Recordset.Fields(1) = Trim(txtPassWord.Text)
Adodc2.Recordset.Fields(2) = Trim(ComboListRights.Text)
Adodc2.Recordset.Update
Adodc2.Refresh
FrmUserManage.Adodc2.Recordset.Update
FrmUserManage.Adodc2.Refresh
MsgBox "添加用户成功", vbOKOnly + vbInformation, "提示"
txtUserName.Text = ""
txtPassWord.Text = ""
txtPassWord2.Text = ""
ComboListRights.Text = ComboListRights.List(0)
txtUserName.SetFocus
Else
MsgBox ("该用户已存在,请换其他用户名!")
txtUserName.Text = ""
End If
End If
End If
+++++++++++++++++++++++++++
by the way 你写的真罗嗦
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询