Here is a class to SQL use an access database:
Class MyDB
Public DBName As String
Private con As New OleDbConnection(ConStr)
Sub New(ByVal DBN)
DBName = DBN
End Sub
Private Function ConStr()
ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBName & ";"
End Function
Private Sub ConInit()
If con.State <> ConnectionState.Open Then
con.ConnectionString = ConStr()
con.Open()
End If
End Sub
Function SQLSelect(ByVal sqlStr As String) As OleDbDataReader
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
ConInit()
cmd = New OleDbCommand(sqlStr, con)
SQLSelect = cmd.ExecuteReader
End Function
Function SQLSelect_Item(ByVal Field As String, ByVal Table As String, ByVal Where As String)
Dim dr As OleDbDataReader
dr = SQLSelect("Select " & Field & " from " & Table & " where " & Where)
If dr.Read Then
SQLSelect_Item = dr(0)
Else
SQLSelect_Item = vbEmpty
End If
End Function
Function SQLSelect_Item(ByVal sqlStr As String)
Dim dr As OleDbDataReader
dr = SQLSelect(sqlStr)
If dr.Read Then
SQLSelect_Item = dr(0)
Else
SQLSelect_Item = vbEmpty
End If
End Function
End Class
Example:
dim i as new MyDB("C:/db.accdb")
msgbox(i.SQLSelect_Item("SELECT * FROM ORDERS WHERE ORDERSTATUS = 'PENDING'"))