473,382 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

running a query in access through code

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
5 10935
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
Thanks for the quick response

c(_)
Nov 20 '05 #3
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: tukaram.thatikonda | last post by:
Hi Guys, I have written a small windows application in VB.Net to test ADO.Net performance while executing long running query. The query works most of the time but fails sometime. I am trying...
4
by: Kory | last post by:
How do you stop a long running query with a SQLConnection or SQLCommand? Calling Close on either just waits until the query is done. Is there a way to stop it? The following on a long query ...
1
by: jnikle | last post by:
I have a parameter query named "qry_employee_info_reports" that I need to run in the OnOpen event of a form. I'm after its total number of records. The query's got several joins in it, and one of...
1
by: rdemyan via AccessMonster.com | last post by:
My application has a table that contains information on buildings. The building data comes from another database and is imported from a spreadsheet into my application. Originally, I thought...
6
by: DeanL | last post by:
Hi All, How do you run a SELECT query from code? I know that DoCmd.RunSQL only works with action or DDF queries but I need to run a query from VBA and add variables into the query as defined by...
1
by: maxvalery | last post by:
Hi, Looking for a quick and dirty on running an Access database as a linked server in SQL Server. Basically, the majority of my stuff is in SQL Server, but there is one lingering...
8
by: John | last post by:
Hi I am using the below code to run a sql on an underlying access table; insStr = "INSERT INTO ( Action, , , Request_Date ) " & _ "VALUES (""Modify Client"", 93, ""Administrator"", Now())"...
0
by: Prabhakar78 | last post by:
How to tune long running query?Please any one can provide me the steps to tune long running query in DB2 V9.1.0 and the environment is AIX (OS)
1
by: ezderek | last post by:
For many years if I wanted to run an action query from code, I've used code something like this --- dim qd as query dim sSQL as string dim db as database set db = currentdb() sSQL = "UPDATE...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.