running Access Queries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Through Visual Basic code can I run an Microsoft Access query? If so, how?

Thanks in advance
bbdobuddy
 
Is it a pre-existing query in Access, or are you wanting to pass an SQL
query to an Access table?

If it's the latter, you make an OLEDB connection to the Access database,
create an OLE command reference, and set the command text to your SQL query,
then execute the command.
 
It is a pre-exitsting query in Access.

Jason said:
Is it a pre-existing query in Access, or are you wanting to pass an SQL
query to an Access table?

If it's the latter, you make an OLEDB connection to the Access database,
create an OLE command reference, and set the command text to your SQL query,
then execute the command.
 
¤ Hi,
¤
¤ Through Visual Basic code can I run an Microsoft Access query? If so, how?
¤

The following executes a SELECT query and populates a DataTable and DataGrid:

Dim AccessConn As System.Data.OleDb.OleDbConnection

AccessConn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db1.mdb")

AccessConn.Open()

Dim AccessCommand As New System.Data.OleDb.OleDbCommand("qryTable1", AccessConn)
AccessCommand.CommandType = CommandType.StoredProcedure

Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter

With da
.SelectCommand = AccessCommand
End With

Dim ds As New DataSet("QueryTables")
da.Fill(ds, "Table1")

DataGrid1.SetDataBinding(ds, "Table1")

AccessConn.Close()


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top