Hi
Ive got the following Code , When I atempt to run it in visual basic 2005 express edition I get the following error "oledbexception was unhandled , could not find file c:\documents and settings\teresa\desktop\mathstutor\bin\mathstutos.mdb.
-------
Ive got the following Code , When I atempt to run it in visual basic 2005 express edition I get the following error "oledbexception was unhandled , could not find file c:\documents and settings\teresa\desktop\mathstutor\bin\mathstutos.mdb.
-------
VB.NET:
Imports System.Data
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Drawing.Drawing2D
Module mdlMain
Public g As Graphics
Public PupilID As Integer, PupilName As String
Private connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MathsTutor.mdb;Persist Security Info=True")
Public Sub DrawGradient(ByVal f As Object)
g = f.CreateGraphics()
Dim myBrush As New LinearGradientBrush(New Point(0, 0), New Point(f.Width, f.Height), Color.DeepSkyBlue, Color.DodgerBlue)
Dim myRectangle As New Rectangle(0, 0, f.Width, f.Height)
g.FillRectangle(myBrush, myRectangle)
End Sub
Public Function Authenticate(ByVal strPwd As String) As Boolean
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand("Select Pass From Admin", connection)
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Do While myReader.Read
If strPwd.ToString = myReader(0).ToString Then
myReader.Close()
connection.Close()
Return True
Else
myReader.Close()
connection.Close()
Return False
End If
Loop
End Function
Public Sub DisplayPupils(ByVal lstPupils As ListBox)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand("Select * From Pupils", connection)
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
lstPupils.Items.Clear()
Do While myReader.Read
lstPupils.Items.Add(myReader(1).ToString)
Loop
myReader.Close()
connection.Close()
End Sub
Public Sub AddPupil(ByVal strName As String)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO Pupils(PupName) VALUES('" & strName & "')"
cmd.Connection = connection
cmd.ExecuteNonQuery()
End Sub
Public Sub DelPupil(ByVal strName As String)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "DELETE FROM Pupils WHERE PupName = '" & strName & "'"
cmd.Connection = connection
cmd.ExecuteNonQuery()
End Sub
Public Sub RenamePupil(ByVal strName As String, ByVal strNewName As String)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "UPDATE Pupils SET pupName = '" & strNewName & "' WHERE PupName = '" & strName & "'"
cmd.Connection = connection
cmd.ExecuteNonQuery()
End Sub
Public Function CheckName(ByVal strName As String) As Boolean
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand("Select pupID, pupName From Pupils", connection)
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Do While myReader.Read
If LCase(strName.ToString) = LCase(myReader(1).ToString) Then
PupilID = myReader(0)
PupilName = myReader(1).ToString
myReader.Close()
connection.Close()
Return True
End If
Loop
myReader.Close()
connection.Close()
Return False
End Function
Public Sub AddResult(ByVal pupID As Integer, ByVal ExamType As String, ByVal strQuestion As String, ByVal intAnswer As Integer, ByVal strAnswerMode As String)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "INSERT INTO Results(pupID, ExamType, QuestionString, Answer, AnswerMode) VALUES(" & pupID & ",'" & ExamType & "','" & strQuestion.ToString & "'," & intAnswer & ",'" & strAnswerMode & "')"
cmd.Connection = connection
cmd.ExecuteNonQuery()
End Sub
Public Sub DisplayResults(ByVal grdResult As DataGrid)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand("Select Format(ExamDt,'mm/dd/yyyy') as ExamDate, ExamType, QuestionString, Count(Answer) as Attempts From Results WHERE pupID = " & PupilID & " Group BY Format(ExamDt,'mm/dd/yyyy'), ExamType, QuestionString ORDER by Format(ExamDt,'mm/dd/yyyy')", connection)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet("Results")
da.Fill(ds, "Results")
grdResult.DataSource = ds.Tables(0)
connection.Close()
End Sub
Public Sub DisplayChildResults(ByVal grdResult As DataGrid, ByVal strQuestion As String, ByVal strExamType As String)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand("Select QuestionString, Answer, AnswerMode From Results WHERE pupID = " & PupilID & " AND QuestionString = '" & strQuestion & "' AND ExamType = '" & strExamType & "'", connection)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet("Results")
da.Fill(ds, "Results")
grdResult.DataSource = ds.Tables(0)
connection.Close()
End Sub
Public Sub DelResult(ByVal strQuestion As String, ByVal strExamType As String)
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand
cmd.CommandText = "DELETE FROM Results WHERE pupID = " & PupilID & " AND QuestionString = '" & strQuestion & "' AND ExamType = '" & strExamType & "'"
cmd.Connection = connection
cmd.ExecuteNonQuery()
End Sub
Public Function ChangePassword(ByVal strOldPwd As String, ByVal strNewPwd As String, ByVal strConfirmPwd As String) As Boolean
If connection.State = ConnectionState.Closed Then connection.Open()
Dim cmd As New OleDbCommand("Select Pass From Admin", connection)
Dim myReader As OleDbDataReader = cmd.ExecuteReader()
Do While myReader.Read
If strOldPwd.ToString = myReader(0).ToString Then
If strNewPwd = strConfirmPwd Then
myReader.Close()
Dim cmdUpdate As New OleDbCommand
cmdUpdate.CommandText = "UPDATE Admin SET Pass = '" & strNewPwd & "'"
cmdUpdate.Connection = connection
cmdUpdate.ExecuteNonQuery()
Return True
Exit Function
Else
MsgBox("New Password and Confirm Password Mismatch!", MsgBoxStyle.Information)
myReader.Close()
Return False
Exit Function
End If
Else
MsgBox("Old Password is Incorrect!", MsgBoxStyle.Exclamation)
myReader.Close()
connection.Close()
Return False
Exit Function
End If
Loop
End Function
End Module
Last edited by a moderator: