i am working on medical billing and coding project.i am at login page right now.
i create form and code but i had error for InvalidOperationExcepmtion was unhandled.
i am really thankful for help who will give.
my code is here :
Imports System.Data.OleDb
Public Class login
Inherits System.Windows.Forms.Form
Dim iCount As Integer
Dim frmMain As New Welcomeadmin
Private Sub btnlogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogon.Click
Dim ConString As String = "Provider=Microsoft.jet.OLEDB.4.0;Password;userid=Admin;Data Source=C:\project.mdb"
Dim DBCon As New OleDb.OleDbConnection(ConString)
g_login = Me.txtuserid.Text
Dim strPassword As String = Me.txtpassword.Text
If g_login = "" Or strPassword = "" Then
MessageBox.Show("You are missing Information.Please check both UserId and Password fields are filed out.", "Missing Info")
Me.txtuserid.Focus()
Return
End If
Dim strsql As String = "SELECT [userid],[password] FROM tbluser WHERE [userid]='" & g_login & "'"
Dim cm As New OleDb.OleDbCommand(strsql, DBCon)
Dim dr As OleDb.OleDbDataReader
Dim valid As Boolean = False
Dim HasRows As Boolean = False
Try
DBCon.Open()
dr = cm.ExecuteReader
If dr.HasRows Then
While dr.Read
If strPassword = dr.Item("password") Then
valid = True
End If
End While
HasRows = True
End If
dr.Close()
Catch exO As OleDb.OleDbException
MessageBox.Show(exO.Message)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If DBCon.State = ConnectionState.Open Then
DBCon.Close()
End If
cm = Nothing
dr = Nothing
DBCon.Dispose()
GC.Collect()
End Try
iCount = iCount + 1
If valid = True Then
Me.Hide()
frmMain.Show()
ElseIf iCount = 3 Then
MessageBox.Show("Contact Admin !", "Invalid Info")
Me.Close()
ElseIf HasRows = False Then
MessageBox.Show("Invalid User Id,try again !", "Invalid Info")
Me.txtuserid.Focus()
Me.txtuserid.Text = ""
Me.txtpassword.Text = ""
Else
MessageBox.Show("Invalid Password, try again !", "Invalid Info")
Me.txtpassword.Focus()
Me.txtpassword.Text = ""
End If
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
Me.Close()
End Sub
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ProjectDataSet.tbluser' table. You can move, or remove it, as needed.
' Me.TbluserTableAdapter.Fill(Me.ProjectDataSet.tbluser)
End Sub
End Class