Hello,
I am kinda new to vb net 2003 and programming in general. I am working on a school project and trying to code my login form to compare the string entered with the data in my password table in a VideoInc database.
This is what i have:
' Must add data namespaces.
' This one for data in general.
Imports System.Data
' This one for OleDB which handles Microsoft Access.
Imports System.Data.OleDb
Public Class frmLogin
Inherits System.Windows.Forms.Form
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim connectionString As String = _
"Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = " & Application.StartupPath & "\VideoInc.mdb;" & _
"User ID = Admin;" & _
"Password = "
Dim logInOleDbConnection As New OleDbConnection(connectionString)
' Create a ADO.NET OleDbCommand.
Dim sqlQueryString As String = "SELECT * FROM Password WHERE " & _
"Name = '" & txtName.Text & "' " & _
"AND Password = '" & txtPassword.Text & "'"
Dim sqlCommand As New OleDb.OleDbCommand(sqlQueryString, logInOleDbConnection)
' Open the database connection.
logInOleDbConnection.Open()
' Run the sqlCommand.
Dim MyResult As Object
MyResult = sqlCommand.ExecuteScalar
Dim countFound As Integer = CType(MyResult, Integer)
' Close the database connection.
logInOleDbConnection.Close()
' If countFound = 1 a record with a matching Name and Password was found..
If countFound = 1 Then
Me.Hide()
FM.mnuFile.Enabled = True
FM.mnuSystemAdmin.Enabled = True
FM.mnuOperations.Enabled = True
FM.mnuFrontOffice.Enabled = True
Else
MsgBox("The information is incorrect. Please try again", vbCritical + vbOK, "Incorrect Information")
For Each ctl As Control In Me.Controls
If TypeOf ctl Is TextBox Then
CType(ctl, TextBox).Clear()
End If
Next
Me.txtName.Focus()
End If
However everytime I try to run this it comes up with this OleDbException
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
and highlights this line in my code:
MyResult = sqlCommand.ExecuteScalar
Can anybody please kindly help me have a look at this code at tell me what I may doing wrong? Also is there a way for me to to confirm that my data source path is correct? Thanks for your anticipated help
I am kinda new to vb net 2003 and programming in general. I am working on a school project and trying to code my login form to compare the string entered with the data in my password table in a VideoInc database.
This is what i have:
' Must add data namespaces.
' This one for data in general.
Imports System.Data
' This one for OleDB which handles Microsoft Access.
Imports System.Data.OleDb
Public Class frmLogin
Inherits System.Windows.Forms.Form
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim connectionString As String = _
"Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = " & Application.StartupPath & "\VideoInc.mdb;" & _
"User ID = Admin;" & _
"Password = "
Dim logInOleDbConnection As New OleDbConnection(connectionString)
' Create a ADO.NET OleDbCommand.
Dim sqlQueryString As String = "SELECT * FROM Password WHERE " & _
"Name = '" & txtName.Text & "' " & _
"AND Password = '" & txtPassword.Text & "'"
Dim sqlCommand As New OleDb.OleDbCommand(sqlQueryString, logInOleDbConnection)
' Open the database connection.
logInOleDbConnection.Open()
' Run the sqlCommand.
Dim MyResult As Object
MyResult = sqlCommand.ExecuteScalar
Dim countFound As Integer = CType(MyResult, Integer)
' Close the database connection.
logInOleDbConnection.Close()
' If countFound = 1 a record with a matching Name and Password was found..
If countFound = 1 Then
Me.Hide()
FM.mnuFile.Enabled = True
FM.mnuSystemAdmin.Enabled = True
FM.mnuOperations.Enabled = True
FM.mnuFrontOffice.Enabled = True
Else
MsgBox("The information is incorrect. Please try again", vbCritical + vbOK, "Incorrect Information")
For Each ctl As Control In Me.Controls
If TypeOf ctl Is TextBox Then
CType(ctl, TextBox).Clear()
End If
Next
Me.txtName.Focus()
End If
However everytime I try to run this it comes up with this OleDbException
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
and highlights this line in my code:
MyResult = sqlCommand.ExecuteScalar
Can anybody please kindly help me have a look at this code at tell me what I may doing wrong? Also is there a way for me to to confirm that my data source path is correct? Thanks for your anticipated help