我在VB.Net的LogIn表单中。但是当我尝试登录时出错。 错误显示
InvalidOperationException未处理
我正在使用Microsoft Access数据库。
当我运行程序时,它没有说出哪条线路有错误 请帮助我...我非常感谢你,并提前感谢。
以下是我的代码:
Imports System.Data.OleDb
Public Class login
Sub koneksi()
conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\bin\Debug\db.accdb;Persist Security Info=True")
conn.Open()
End Sub
Private Sub login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
koneksi()
End Sub
Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
If txtstaffid.Text = "" Or txtpassword.Text = "" Then
MsgBox("Please insert your staff ID and password")
txtstaffid.Focus()
Exit Sub
Else
cmd = New OleDbCommand("select * from user where staffid='" & Rep(txtstaffid.Text) & "' and pass='" & Rep(txtpassword.Text) & "'", conn)
rd = cmd.ExecuteReader ' Error occurs here !!!
rd.Read()
If rd.HasRows Then
MsgBox("Successful Login!")
Me.Visible = False
menuUtama.Show()
menuUtama.Label1.Text = rd("role")
Clear()
Else
MsgBox("Wrong staff ID or password")
Clear()
End If
End If
End Sub
Sub clear()
txtstaffid.Text = ""
txtpassword.Text = ""
End Sub
这是我的module1.vb
:
Imports System.Data.OleDb
Module Module1
Public conn As OleDbConnection
Public cmd As OleDbCommand
Public rd As OleDbDataReader
Public Function Rep(ByVal kata As String) As String
Rep = Replace(kata, "'", "''")
End Function
End Module
错误显示在
行rd = cmd.ExecuteReader