我用vb.net编写了一个登录界面,输入用户名和密码都正确,可是运行是都是提示用户名或密码错误。很急,请大家帮帮忙!!!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
checkFormat()
End Sub
Sub checkFormat()
If TextBox1.Text = " " Or TextBox2.Text = " " Then
MsgBox("用户名和密码不能为空")
ElseIf ComboBox1.Text = "" Then
MsgBox("请选择用户权限")
Else
checkLoginName()
End If
End Sub
Sub checkLoginName()
Dim str As String
str = "Data Source =localhost; Initial Catalog=酒吧信息管理系统; integrated Security=true"
Dim con As New SqlConnection(str)
con.Open()
Dim sql As String = "select * from user_info where 用户名=' " & TextBox1.Text.ToString().Trim() & " 'and 密码=' " & TextBox2.Text.ToString().Trim() & " ' and 用户权限 ='" & ComboBox1.Text.ToString().Trim() & "' "
Dim cmd As New SqlCommand(sql, con)
Dim reader As SqlDataReader
reader = cmd.ExecuteReader
If reader.Read() = True Then
Me.Hide()
main.Show()
main.Text = "123酒吧欢迎你" & ComboBox1.Text & "--" & TextBox1.Text
Else
MsgBox("登录失败,请检查用户名和密码是否正确")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
我检查了号多遍就是不知道问题在哪。好多同学都遇到这样的问题。请高手帮忙。