Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP Classic connecting to Access Query with Parameter

Posted on 2011-09-21
2
320 Views
Last Modified: 2012-05-12
OK, I have to remember how to do this.

Using ASP Classic Connecting to Access 2010

Everything works until I pass in a parameter.  

I am trying to loop through a list of Name/Value pairs and pass them in against a query.

The query runs fine and the ASP connects and returns without the parameter.

Any help would be greatly appreciated.
Call with this:

    nList =     "@schoolID,"
    vList =     "1,"
    ar = get_Records("ps_selectSchool", nList, vList, 50, set_CONXStrng() )

    if isnull(ar) then response.Write "yeP"
    
    for x = 0 to ubound(ar,2)
        response.Write ar(0,x) & " " & ar(1,x) & "<br>"
    next




function here:

public function get_Records( proc_name, nList, vList, pSize, strconn )
    dim objcmd
    dim objrs
    dim objparam
    dim n, v, r
    dim theName, theValue
	
	set objcmd = server.CreateObject("ADODB.command")
	with objcmd
		.activeconnection = strconn
		.commandtext = proc_name
		.commandtype = adcmdstoredproc
		
		'add paramaters if exist
	    if Len(nList) > 0 then 
	        n = split(nList,",")
	        v = split(vList,",")
	        
	        for x = 0 to ubound(n)
	            theName =  n(x) 
	            theValue = v(x)
	            if len(theName) > 1 then
	                'response.Write n(x) & " " & v(x) & "<br>"
	                set objparam = .createparameter
	                objparam.name = n(x)
                    objparam.Type = adBoolean
                    objparam.Direction = adParamInput
                    objparam.size = pSize
                    objparam.Value = v(x)
	                .Parameters.Append objparam
	            end if
	        next
	    end if
        
        'execute the recordset
        'set objrs = server.CreateObject("ADODB.recordset")
        set objrs = objcmd.execute()
        if objrs.bof = false AND objrs.eof = false then
	        r = objrs.getrows
            else
            r = null
	    end if           
        
        set strconn = NOTHING
	    set objrs = NOTHING
	    set objcmd = NOTHING   
	    
	    get_Records = r
 	end with
 end function


Query Here:

SELECT tblSchool.schoolID, tblSchool.schoolName
FROM tblSchool
WHERE (((tblSchool.schoolID)=[@schoolid]));

Open in new window

0
Comment
Question by:skillilea
2 Comments
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 500 total points
ID: 36579118
This is surely all down a single, yet not necessarily obvious assumption... (Not obvious because there are other things you've added as far as parameter resolution... but they're not playing a part - they're seemingly fine.)
You have the assignment:
objparam.Type = adBoolean

You're presupposing that all passed paramters will be Boolean.  This is then resolved into a boolean value and it's not matching the ID you actually pass. (Your 1 will be resolved into -1, as will any other non-zero value.)

This is the problem with generic (iterative) parameter evaluation. You either have to pass in the parameter type as another function parameter or try to coerce something more generic. (Like "adVariant" :-s)

Cheers.
0
 

Author Closing Comment

by:skillilea
ID: 36579571
nice job....copying code from old apps makes you stay up late!

well done!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question