Imports System.Data.OleDb

Public Class frmLogin
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim add As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Documents\Visual Studio 2008\Projects\DietTrainer\DietTrainer\DT.mdb.accdb"
Dim dr As OleDbDataReader

Dim SID As String = "admin"
Dim SPSW As String = "admin"
Dim LoginID As String = Me.txtID.Text
Dim LoginPassword As String = Me.txtpsw.Text

Try
cn = New OleDbConnection(add)
cn.Open()
cmd = New OleDbCommand("SELECT ID,Password FROM User", cn)
dr = cmd.ExecuteReader
If LoginID = SID And LoginPassword = SPSW Then
MsgBox("Welcome Admin!")
frmSChoice.Show()
txtID.Text = ""
txtpsw.Text = ""
Me.Hide()
'End If
ElseIf dr.Read = True Then
If LoginID = dr("ID") And LoginPassword = dr("Password") Then
MsgBox("Login Sucessful!")
frmUserChoice.Show()
txtID.Text = ""
txtpsw.Text = ""
Me.Hide()
End If
End If

Catch ex As Exception

End Try
dr.Close()
cn.Close()

'' Above is my VB.net 2008 coding... i have tried several time to login but keep popping
"Object Reference Not Set As An Instance Of Object" once i connect to database.
Can anyone help me to solve this problem?
Thanks!!

This article has been dead for over six months. Start a new discussion instead.