Error with login page.. HELP!!!

shizuka

Member
Joined
Jul 26, 2006
Messages
7
Programming Experience
Beginner
Hi my login page works fine, until i run it again yesterday.. Below is the error it gave.. Any kind soul please help.. I'm a still beginner.. Thanks alot!

An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll

Additional information: The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable.


Below is my code.. the error points to the line in red :

VB.NET:
Dim strUser, strPass, strConn As String
Dim frmMain As New frmHome
Dim dbcon As New OleDbConnection
 
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn += "Data Source=Computer Store.mdb;User Id=Admin; Password=;"
dbcon.ConnectionString = strConn
 
'set up query statement
strUser = "Select * from Storer where StorerID='" & Me.txtUser.Text.Trim & "'"
 
'create an instance of a command
Dim cmdSelectCommand As New OleDbCommand(strUser, dbcon)
dbcon.Open()
 
'execute command
Dim dtLogin As OleDbDataReader = cmdSelectCommand.ExecuteReader
'Reader will return a TRUE if the username matches
If (dtLogin.Read() = True) Then
Dim tempUser, tempPass As String
tempUser = dtLogin.Item("StorerID")
tempPass = dtLogin.Item("EmpPassword")
 
Dim PrivAccess As Short
[COLOR=red]PrivAccess = dtLogin.GetInt16(dtLogin.GetOrdinal("EmpPrivilege"))[/COLOR]
If PrivAccess = 1 Then
MessageBox.Show("Level 1, Login OK!")
Me.Visible = False
frmMain.ShowDialog()
Me.Visible = True
Me.txtUser.Clear()
Me.txtPass.Clear()
Me.txtUser.Focus()
 
Else
MessageBox.Show("Level 2, Login OK")
Me.Visible = False
frmMain.btnCustOrder.Enabled = False
frmMain.btnCustOrder.Visible = False
frmMain.ShowDialog()
Me.Visible = True
Me.txtUser.Clear()
Me.txtPass.Clear()
Me.txtUser.Focus()
End If
Else
MessageBox.Show("Login Fail! Please Try Again.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Me.txtUser.Clear()
Me.txtPass.Clear()
Me.txtUser.Focus()
End If
dtLogin.Close()
dbcon.Close()
 
Last edited by a moderator:
VB.NET:
Dim PrivAccess As Short
PrivAccess = dtLogin.GetInt16(dtLogin.GetOrdinal("EmpPrivilege" ))
If PrivAccess = 1 Then

Why short? Why not just int32 or integer. Besides i think it should read like this....

VB.NET:
PrivAccess = dtLogin.GetInt32(The Zero baed index of the column in the database where this info is stored)

I have to ask, why on earth are you doing it this way? If i may say so it looks a bit messy. If I were you i'd look into re-writing this part. But this time check out using the DISTINCT keyword in SQL i'm asuming that since this is a login screen that the rows in the table will all be unique. So all you need to do is check for one particular row.
 
Back
Top