Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Query in access ans ASP ??


Message #1 by "Vandael Tim" <Vandael_tim@h...> on Tue, 26 Mar 2002 15:53:26
Helle all,

i am pretty new to ASP.

I have a question, for my final exam at school i have to make an 
application in ASP.

Now i wanne know if it is possible to have ASP execute a query that has 
been written is access.

The query codes are in access so ASP doesnt have to perform the whole code.
Just activate the query and write the results.

Thnx

Vandael Tim
Message #2 by "Rob Parkhouse" <rparkhouse@o...> on Thu, 28 Mar 2002 05:19:26
> Helle all,

> i am pretty new to ASP.

> I have a question, for my final exam at school i have to make an 
a> pplication in ASP.

> Now i wanne know if it is possible to have ASP execute a query that has 
b> een written is access.

> The query codes are in access so ASP doesnt have to perform the whole 
code.
J> ust activate the query and write the results.

> Thnx

> Vandael Tim
Message #3 by "Rob Parkhouse" <rparkhouse@o...> on Thu, 28 Mar 2002 06:16:01
Try something like the following code:

        Dim strConnect, objConn, objRs, objComm

	strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=rob;" & _
		      "Data Source=C:\Surv\Surv.mdb;" & _
		      "Persist Security Info=False;Jet OLEDB:System 
database=c:\surv\adm.mdw"

	' Create Connection and Recordset objects
	Set objConn = Server.CreateObject("ADODB.Connection")
	Set objRS = Server.CreateObject("ADODB.Recordset")
	
	' Connect to the database
	objConn.Open strConnect

	Set objComm = Server.CreateObject("ADODB.Command")
	objComm.ActiveConnection = strConnect
	objComm.CommandText = "qryName"       ' Access query
	objComm.CommandType = adCmdStoredProc

        ' if the query has criteria (say referring to controls on forms) 
you have to establish the parameters and give them a value. Otherwise 
leave the following bit relating to parameters out.
		
	' define the query parameters
	Set objParam = objComm.CreateParameter("[Forms]![dlgIndiv]!
[CGid]",adVarChar,adParamInput,50)
	objCommParameters.Append objParam
	Set objParam = objComm.CreateParameter("[Forms]![dlgIndiv]!
[Empid]",adVarChar,adParamInput,50)
	objComm.Parameters.Append objParam
		
	' set the query parameter values CGID and EmpID are variables that 
should have their value set
	objComm.Parameters("[Forms]![dlgIndiv]![CGid]") = CGid
	objComm.Parameters("[Forms]![dlgIndiv]![Empid]") = Empid

	Set objRS = objComm.Execute					
	' execute the query
	Set objParam = Nothing
	Set objComm = Nothing
		
	Do Until objRS.EOF         ' do something with recordset
Message #4 by "Vandael Tim" <vandael_tim@h...> on Thu, 28 Mar 2002 10:17:42
Thnx a lot for the reply,
but there is still one problem,
i am a newbie! :-)

I understand the whole code, except this code here :

' if the query has criteria (say referring to controls on forms)
' you have to establish the parameters and give them a value. Otherwise
' leave the following bit relating to parameters out.

' define the query parameters
Set objParam = objComm.CreateParameter("[Forms]![dlgIndiv]!
[CGid]",adVarChar,adParamInput,50)
objCommParameters.Append objParam
Set objParam = objComm.CreateParameter("[Forms]![dlgIndiv]!
[Empid]",adVarChar,adParamInput,50)
objComm.Parameters.Append objParam

' set the query parameter values CGID and EmpID are variables that
'should have their value set
objComm.Parameters("[Forms]![dlgIndiv]![CGid]") = CGid
objComm.Parameters("[Forms]![dlgIndiv]![Empid]") = Empid
]![dlgIndiv]![Empid]") = Empid

I am able to perform a access query and output the data, but i cant 
understand how you can include variables that you have to put in on a form.
I think the above code is for such a reason, but i dont get the code ! :((

Sorry for the questions!!!

And Thnx for the replies !!!!

Tim

  Return to Index