用户登陆问题求助
本人学习学做一个登陆窗体,运行时提示用户名或密码错,请大家帮我看下是哪个地方写错了,以下是原码:Public Class Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnStr As String, cmdtext As String
cnStr = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath() & "\database.mdb"
Dim cn As New OleDbConnection(cnStr)
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim dt As New DataTable("user")
Try
cn.Open()
cmdtext = "select * from user where name='" & nametext.Text & "' and password='" & pwtext.Text & "'"
cmd = New OleDbCommand(cmdtext, cn)
dr = cmd.ExecuteReader
If dr.HasRows Then
MessageBox.Show("登陆成功", "系统登陆", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
dr.Close()
End If
Catch ex As Exception
MessageBox.Show("用户名或密码错误", "系统登陆", MessageBoxButtons.OK, MessageBoxIcon.Information)
nametext.Text = Nothing
pwtext.Text = Nothing
nametext.Focus()
Finally
cn.Close()
cn = Nothing
End Try
End Sub