How to execute SQL Statemnt on MS Access DB ?

You can do it through the following

Add an Imports System.Data.Oledb to your class

Dim connection as new oledbconnection()
connection.connectionstring = "Supply the connection to your db"

Dim command as new oledbcommand()
command.connection = connection
command.commandtype = commandtype.text
command.commandtext = "Your SQL Query here"

finally execute the command, you may have two scenarios
If you are inserting or updating to the database
you may not need to return anything so type

command.ExecuteNonQuery()

if you are doing a select statement then do the following
declare a reader to hold your data
Dim reader as OledbDataReader
set the reader to the result of your query
reader = command.ExecuteReader()
now the reader has the data returned

finally close the reader and the connection

reader.close()
connection.close()
 
Back
Top