Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP and UPDATE QUERY

Status
Not open for further replies.

kjoost001

Programmer
Apr 11, 2002
19
0
0
US
I am trying to execute an update query already stored in MS Access from an .asp page. Is this possible? Can I use QueryDef? If so, i have no clue on syntax. please help if you can. thanks, ken
 
with your active connection to your Access db and recordset(objrs) the code goes something like

objcommand.commandtext ="qryYourQuery"
objcommand.commandtype = adCmdStoredProc
set objrs = objcommand.execute

where "qryYourQuery" is the name of the stored query

Hope this is helpful

Andy
 
thanks for the response awithers, however, i have attached my code with your response, and i stillreceive internal server error. here is my code ( can you use the execute method with an update query type?)

thanks again.


<%
Option Explicit
%>
<%
Dim dcnDB
Dim sDatabaseLocation
Dim objrs

Set dcnDB = Server.CreateObject(&quot;ADODB.Connection&quot;)
sDatabaseLocation = Server.MapPath(&quot;FFLDB1.mdb&quot;)
dcnDB.Open(&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; + sDatabaseLocation)

dcnDB.commandtext =&quot;qry_test1&quot;
dcnDB.commandtype = adCmdStoredProc
set objrs = objcommand.execute
%>
<html>
<body>
Test complete.
</html>
 
There is a easier way to do it, that will allow you to skip the adCmdStoredProc section.

myconnection.execute(syntax of the SQL statement you want to run)

With this you could just declare whatever SQL is in the udpate query, create it as a variable in the code, and run it directly.

SQL = &quot;update mytablename set myfield = myvalue&quot;
myconnection.execute(SQL)


But the catch is that MS Access might not recognize that the update query is a stored procedure. This is evident if you have ever tried to upsize from Access to SQL. It works fine for select based queries, but try to upsize a append/delete/update query, and it freaks out.

You might try putting the call to the update query in a Macro, and then calling the macro through the code that was submitted above. I would think that would have a little bit better result for you. The money's gone, the brain is shot.....but the liquor we still got.
 
I think you need to change the line

set objrs = objcommand.execute

to

set objrs = dcnDB.execute

but have to agree with Dynapen it might be worth copying the sql of the query into the code

Andy



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top