In addition to OriginalGriff's solution, i'd recommend to separate your into
DAL[
^] and
BLL[
^].
The reason why you have to do that is described in referenced articles.
To find out why you get such of error, you have to debug your programme:
Learn to debug using the Visual Studio debugger - Visual Studio | Microsoft Docs[
^]
I guess you've got
oledbexception (0x80040e10)
, which means you did not provide parameter, which is obligatory. See:
OLEDB Errors[
^]
Few notes about your code:
1. Your code does not return the result of
ExecutNonQuery
method, so have no idea if this method has been succeeded.
2. Your code does not have an error handler... It's good programming practice to catch errors by code. Take a look at below code. It's not perfect, but it's good for starters.
Function GetEmployee(Optional ByVal empIdToFind As Integer = 111) Ad DataTable
Dim dt As DataTable = New DataTable()
Try
Dim sConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=[FullFileNameOfMsAccessDatabase];Persist Security Info =False;"
Dim oRdr As OleDbDataReader
Using oConn As OleDbConnection = New OleDbConnection(sConn)
oConn.Open()
Using oComm AS OleDbCommand = New OleDbCommand()
oComm.Connection = oConn
oComm.CommandType = CommandType.Text
oComm.CommandText = "SELECT * FROM MyUsers WHERE EmpId=@empid;"
oComm.Parameters.AddWithValue("@empid", empIdToFind)
oComm.ExecuteNonQuery()
oRdr = oComm.ExecuteReader()
dt.Load(oRdr)
End Using
oConn.Close()
End Using
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Return dt
End Function
Above function requires
empIdToFind
input parameter to be able to return DataTable (complete record).
Note: the order of named/non-named parameters does matter!
3. This code:
If storage.SelectedIndex = 1 Then
groupordner.Visible = True
grouplemari.Visible = False
Else
If storage.SelectedIndex = 2 Then
groupordner.Visible = False
grouplemari.Visible = True
End If
End If
can be simplified into form:
groupordner.Visible = If(storage.SelectedIndex=1, True, False)
grouplemari.Visible = Not groupordner.Visible
See:
If Operator (Visual Basic) | Microsoft Docs[
^]
Good luck!