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'"))

Is there a question?

Is it a tutorial? I am not any senior member here but I think you should contribute your tutorials in tutorials section.
Here
And thanks I was looking for this example, you did it just in perfect time. :) thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.