1)这是我检查用户名和密码的代码,如果匹配则登录。:
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Try
Dim dr As OleDb.OleDbDataReader
Dim cmd As OleDb.OleDbCommand
Dim logQuery As String = ("SELECT * FROM Login_db where Username='" & txtUsername.Text & "'")
cnnOLEDB.Open()
cmd = New OleDb.OleDbCommand(logQuery, cnnOLEDB)
dr = cmd.ExecuteReader
If dr.Read = True Then <-------------------- problem
If txtUsername.Text = dr("Username") Then
If txtPassword.Text = dr("Password") Then
MsgBox("Hii")
End If
Else
MsgBox("Byee")
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
cnnOLEDB.Close()
End Try
End Sub
if dr.read=true then
即使我在我的表中记录了该行,该行也会返回 false ......
2)这是我在登录表中添加新用户的代码
尝试
Dim addUser As String
addUser = "INSERT INTO Login_db(Username,Password) VALUES (@uname,@pswd)"
cnnOLEDB.Open()
Dim _comm As OleDb.OleDbCommand = New OleDb.OleDbCommand(addUser, cnnOLEDB)
_comm.Parameters.AddWithValue("@uname", txtUsername.Text)
_comm.Parameters.AddWithValue("@pswd", txtPasswd.Text)
_comm.ExecuteNonQuery()
cnnOLEDB.Close()
MsgBox("Record Inserted", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox(ex.Message)
cnnOLEDB.Close()
End Try
错误是:插入语句中的语法错误。我找不到我的错误。
请解决我的问题...谢谢..