running Access Queries

G

Guest

Hi,

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

Thanks in advance
bbdobuddy
 
J

Jason

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.
 
G

Guest

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.
 
P

Paul Clement

¤ 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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

joining tables 1
open a Microsoft Access form 4
Visual Basic and Microsoft Access 1
opening a text file 1
progress bar 1
Windows Service 2
criteria in a search query 2
converting a string to integer 1

Top