求VB代码问题: 这是VB+SQL中“登陆界面”代码,麻烦大侠帮我看一下哪里有问题,他老是报错……
具体的编程思路是:点击登陆控件(输入用户名和密码)以后,先在admin表中查询,如果有,跳出form6,如果没有,则到users表里查询,查得到就到form3,查不到,就...
具体的编程思路是:
点击登陆控件(输入用户名和密码)以后,先在admin表中查询,如果有,跳出form6,如果没有,则到users表里查询,查得到就到form3,查不到,就报错……
Dim mysql1 As String = " select * from admin where aname='" & TextBox1.Text & "' and apassword ='" & TextBox2.Text & "'"
Dim mycommand1 As New SqlCommand(mysql1, myconn)
myconn.Open()
Dim myreader1 As SqlDataReader
myreader1 = mycommand1.ExecuteReader
If myreader1.HasRows = True Then
f6.Show()
f1.Hide()
Else
Dim mysql2 As String = " select * from users where name='" & TextBox1.Text & "' and password ='" & TextBox2.Text & "'"
Dim mycommand2 As New SqlCommand(mysql2, myconn)
myconn.Open()
Dim myreader2 As SqlDataReader
myreader2 = mycommand2.ExecuteReader
If myreader2.HasRows = True Then
f3.Show()
f1.Hide()
Dim huiyuuan = TextBox1.Text
Dim pass = TextBox2.Text
huiyuan = huiyuan + myreader2.Item(0)
pass = pass + myreader2.Item(1)
Else
MsgBox("错误的账号或密码信息!")
TextBox1.Text = ""
TextBox2.Text = ""
End If
End If 展开
点击登陆控件(输入用户名和密码)以后,先在admin表中查询,如果有,跳出form6,如果没有,则到users表里查询,查得到就到form3,查不到,就报错……
Dim mysql1 As String = " select * from admin where aname='" & TextBox1.Text & "' and apassword ='" & TextBox2.Text & "'"
Dim mycommand1 As New SqlCommand(mysql1, myconn)
myconn.Open()
Dim myreader1 As SqlDataReader
myreader1 = mycommand1.ExecuteReader
If myreader1.HasRows = True Then
f6.Show()
f1.Hide()
Else
Dim mysql2 As String = " select * from users where name='" & TextBox1.Text & "' and password ='" & TextBox2.Text & "'"
Dim mycommand2 As New SqlCommand(mysql2, myconn)
myconn.Open()
Dim myreader2 As SqlDataReader
myreader2 = mycommand2.ExecuteReader
If myreader2.HasRows = True Then
f3.Show()
f1.Hide()
Dim huiyuuan = TextBox1.Text
Dim pass = TextBox2.Text
huiyuan = huiyuan + myreader2.Item(0)
pass = pass + myreader2.Item(1)
Else
MsgBox("错误的账号或密码信息!")
TextBox1.Text = ""
TextBox2.Text = ""
End If
End If 展开
1个回答
展开全部
正确的源码
Private Sub Cmd_Click() '确定按钮鼠标单击事件代码
If txt1.Text = "user" Then '若用户名文本框输入正确
Txt2.SetFocus '密码文本框激活
Elself Txt1.Text <> "user" Then
Txt1.Setfocus
End If
简化后的代码
If Txt1.Text="user" then
Txt2.Setfocus
Else
Txt1.Setfocus
End If
Private Sub Cmd_Click() '确定按钮鼠标单击事件代码
If txt1.Text = "user" Then '若用户名文本框输入正确
Txt2.SetFocus '密码文本框激活
Elself Txt1.Text <> "user" Then
Txt1.Setfocus
End If
简化后的代码
If Txt1.Text="user" then
Txt2.Setfocus
Else
Txt1.Setfocus
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询