I am trying to query an access database to find in a row exists in the database and if the value of IsManager = True or not. I'm new to using databases so any help is good thanks yall :) <3
Try
Dim SQL As String
Dim CMD As New OleDb.OleDbCommand
Dim DT As New DataTable
Dim D_A As New OleDb.OleDbDataAdapter
MainMenu.Con.Open()
SQL = ("SELECT * FROM Staff WHERE Login = " & ID)
CMD.Connection = MainMenu.Con
CMD.CommandText = SQL
D_A.SelectCommand = CMD
D_A.Fill(DT)
Catch ex As Exception
MsgBox(ex.Message)
Finally
MainMenu.Con.Close()
End Try
CodePudding user response:
Don't fill a DataTable and then retrieve a field inside it. Insert in a variable the value you want to get.
Dim IsManager as Boolean
Try
Dim SQL As String
Dim CMD As New OleDb.OleDbCommand
Dim D_A As New OleDb.OleDbDataAdapter
SQL = ("SELECT IsManager FROM Staff WHERE Login = " & ID)
CMD.Connection = MainMenu.Con
CMD.CommandText = SQL
D_A.SelectCommand = CMD
MainMenu.Con.Open()
Dim Dr as OleDbDataReader = CMD.ExecuteReader
Dr.Read()
IsManager = Dr.Item("IsManager")
Dr.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
MainMenu.Con.Close()
End Try
