By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

running a query in access through code

P: n/a
Hi all,

I'm trying to execute a query in VB.Net that is stored in Access.

I already have a connection to the database ("C:\Tmp\Testdatabase.mdb") and now I'm looking to execute the query ("qryTest") that creates a table in Access. Can anyone give me the code that will do such a thing?

Thanks in advance,
c(_)
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

Dim conn As OleDbConnection

Dim strConn As String

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = C:\Tmp\Testdatabase.mdb;"

conn = New OleDbConnection(strConn)

Dim cmd As New OleDbCommand("qryTest", conn)

conn.Open()

cmd.ExecuteNonQuery()

conn.Close()

Ken

---------------------------

"CoffeeMug" <an*******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hi all,

I'm trying to execute a query in VB.Net that is stored in Access.

I already have a connection to the database ("C:\Tmp\Testdatabase.mdb")
and now I'm looking to execute the query ("qryTest") that creates a table
in Access. Can anyone give me the code that will do such a thing?

Thanks in advance,
c(_)

Nov 20 '05 #2

P: n/a
Thanks for the quick response

c(_)
Nov 20 '05 #3

P: n/a
Hi Ken

Thanks again for the reply..
I'm getting the following error

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE
This error occurs when VB tries to execute the code cmd.ExecuteNonQuer

The database is not in use, and the query is pretty straightforward
It copies data from a linked (through ODBC) table (pwd and UID are stored) and puts it in a new table..

Can you help me out please

Thanks in advance
Vincent c(_)
Nov 20 '05 #4

P: n/a
On Wed, 21 Jan 2004 05:46:08 -0800, CoffeeMug <an*******@discussions.microsoft.com> wrote:

Hi Ken,

Thanks again for the reply...
I'm getting the following error:

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'
This error occurs when VB tries to execute the code cmd.ExecuteNonQuery

The database is not in use, and the query is pretty straightforward:
It copies data from a linked (through ODBC) table (pwd and UID are stored) and puts it in a new table...

Can you help me out please?

You may want to post your code and the contents of your Access QueryDef.
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #5

P: n/a
Hi,

Sorry forgot this line add it before you use the the oledbcommand.
cmd.CommandType = CommandType.StoredProcedure

Ken

--------------------------

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OC*************@tk2msftngp13.phx.gbl...
Hi,

Dim conn As OleDbConnection

Dim strConn As String

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = C:\Tmp\Testdatabase.mdb;"

conn = New OleDbConnection(strConn)

Dim cmd As New OleDbCommand("qryTest", conn)

conn.Open()

cmd.ExecuteNonQuery()

conn.Close()

Ken

---------------------------

"CoffeeMug" <an*******@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hi all,

I'm trying to execute a query in VB.Net that is stored in Access.

I already have a connection to the database ("C:\Tmp\Testdatabase.mdb")
and now I'm looking to execute the query ("qryTest") that creates a table
in Access. Can anyone give me the code that will do such a thing?

Thanks in advance,
c(_)


Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.