EziData Solutions

Web, NET and SQL Server

Connecting to an Access database

Class Declarations

Imports System.Data.OleDb

Function Code

'declare the Sql data controls

Dim conn As New OleDbConnection()

Dim cmd As New OleDbCommand


'declare and initialise the connection string

Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|Users.mdb"


'assign the string and open the SQL connection control

conn.ConnectionString = strConnection



'set the command type depending on the query being used

'For dynamically created SQL

cmd.CommandType = CommandType.Text

cmd.CommandText = "SELECT * FROM tablename WHERE FilterBy LIKE @ParamName"



'set the connection to use with the command

cmd.Connection = conn


'utilise the command in one of the methods below...

Posted: Oct 06 2009, 20:16 by CameronM | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Access