Link to home
Start Free TrialLog in
Avatar of dcgimo
dcgimo

asked on

Expand current search page to pass many parameters to a stored procedure

Currently, I have a search page that has ONE input box where a user enters either a PIN, name or address to search for.  The page then passes the one parameter from the input box to a stored procedure and returns a list of matches.  My data is farily messy, so this is not working for me.  Instead, I'd like to modify my page to have several input boxes (one for PIN, one for first name, one for last name, one for street number and one for street name).  I have developed a stored procedure to accept these paramters and done extensive testing and it is working exactly how I'd like.  My problem is that I am now struggling with modifying my search page to have these 5 input boxes (instead of one), one submit button and then pass the 5 parameters (instead of one) to the new stored procedure on click on the submit button.

My new stored procedure: (the previous SP was identical, but only accepted one parameter...@strSearch)

CREATE PROCEDURE SearchData_proc
@strPIN varchar(10),
@strFirstName varchar(30),
@strLastName varchar(30),
@strHouseNum varchar(10),
@strStreet varchar(30)
as
SELECT first_name,  last_name, parcel_number, housenum, street
from SearchView
WHERE
parcel_number = @strPIN or
first_name LIKE + '%' + @strFirstName +'%' and
last_name LIKE + '%' + @strLastName +'%' and
HouseNum LIKE + '%' + @strHouseNum +'%' and
street LIKE + '%' + @strStreet +'%'
GO


This is my current Search.asp page that needs to be modified:

<%
     'check to make sure the user is logged in
If Session("blnValidUser") <> True Then Response.Redirect("Login.asp")

Dim strURL      ' The URL of this page
Dim strConnect  ' ADO connection
Dim rstSearch   ' ADO recordset
Dim strDBPath  
Dim SQL                  
Dim strSearch   ' The text being searched for

strURL = Request.ServerVariables("URL")
strSearch = Request.QueryString("search")
                        
%>
<p><font size=3><font color=#383798>Please enter a parcel number, name or address to search by:</p>
<form action="<%= strURL %>" method="get">
<input name="search" value="<%= strSearch %>" size="20" />
<input type="submit" value='Search'  />
</form>
<p><font size=2><font color=#383798><u>Examples:</u><br>0101100001<br>Smith<br>
<p><font size=2><font color=#383798> Hint:  if no results are returned, try minimizing your entry. <br>For example...if John Smith returns no results, try searching for Smith.

<%
If strSearch <> "" Then
strDBPath = Server.MapPath("database.mdb")

Set strConnect = Server.CreateObject("ADODB.Connection")
strConnect.Open "Provider=SQLOLEDB; DRIVER=SQLServer; SERVER=; UID=; PWD=; DATABASE=;"
'will change this to connection file when development is done
                        
SQL = "exec searchdata_proc '" & Replace(strSearch, "'", "''") & "%' "
Set rstSearch = strConnect.Execute(SQL)
%>

<%
    response.write("<form name='displayresult' method='POST' action='results.asp'>" & vbcrlf)
    response.write("<select name='id'>" & vbcrlf)
if  rstSearch.eof then
    response.write("<option value=''>No Results</option>" & vbcrlf)
else
    response.write("<option value=''><u>Parcel Number, Owner, Address</option></u>" & vbcrlf)
    do while not rstSearch.eof
        response.write(vbtab & "<option value='" & rstSearch("parcel_number") & "'>" & rstSearch("parcel_number") & " , " & rstSearch("last_name") &  ", "  &rstSearch("first_name") & " , " & rstSearch("house_number") & " " & rstSearch("house_number_suffix") & " " & rstSearch("prefix_directional") & " " & rstSearch("Street_name") & " " & rstSearch("street_suffix") & " " & rstSearch("post_directional") & ", " & rstSearch("community_name") & "</option>" & vbcrlf)
        rstSearch.movenext
    loop
end if
response.write("</select>" & vbcrlf)
response.write("<input type='submit' value='Display Results' />" & vbcrlf)
response.write("</form>" & vbcrlf)
%>
   
<%
      rstSearch.Close
      Set rstSearch = Nothing
      strConnect.Close
      Set strConnect = Nothing
End If

%>
</BODY>
</HTML>
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Here is an example of what you are trying to do. Please take a look at it, and then if you need help converting your code, please let me know.

FtB
SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So, what I have done is to create a command object and then all of the parameters. Then I executed the command. In the above, I am executing a liter sql statement, but you could pass the name of the stored proceedure instead.

FtB
Hi

firstly you might be better off using the command object to execute it and store it in the recordset

Just add the input tto your form...

<form action="<%= strURL %>" method="get">
<input name="PIN" value="<%= strSearch %>" size="20" /><BR>
<input name="FirstName" value="<%= strSearch %>" size="20" /><BR>
<input name="LastName" value="<%= strSearch %>" size="20" /><BR>
<input name="StreetNumber" value="<%= strSearch %>" size="20" /><BR>
<input name="StreetName" value="<%= strSearch %>" size="20" /><BR>
<input type="submit" value='Search'  />
</form>


And add them into the parameter listings in the command object:

<%
...
Dim ObjCmd
Set ObjCmd = Server.createobject("ADODB.command")
Dim StrPin, StrFname, StrLname, StrStreenNum, StrStreetName

strPin = Request.QueryString("Pin")
strFname= Request.QueryString("Firstname")
strLname = Request.QueryString("Lastname")
strStreetNum = Request.QueryString("StreetNumber")
strStreetName = Request.QueryString("StreetName")

objCmd.Activeconnection = Strconnect
objCmd.CommandText = "Search_Proc(" & StrPin & ", " & StrFname & ", " & StrLname & ", " & strStreetNum & ", " & StreetName & ")"
objCmd.CommandType = 04
objCmd.CommandTimeout = 300
SET rstSearch = objCmd.execute

...
%>
Sounds like we have the same idea!

FtB
Avatar of dcgimo
dcgimo

ASKER

Wow, quick responses, thank you!  I will do some testing this these ideas...
Hey ftb, how are you? Sorry, it took me a while to type it so i didnt realise you already posted :o) But yeh, same idea
@apresto--

Fine apresto, how about you? I have been too busy to post of late, but I check in from time to time.

@dcgimo--

Good luck with your testing. There are a lot of good folks in this topic area.

FtB
Avatar of dcgimo

ASKER

FtB- yes, I can't believe how helpful everyone is, it is great!  I'm new to this, so I will probably need some additional help, but I am going to try with the info you and apresto have given me before I ask my follow-up q's.  Once again, thank for the quick response!
@ftb

Yeh im good, I've been busy aswell, i have my first dev job since college but i try to keep up :o)

@Dcgimo

Agreed with ftb, you're well looked after ;o) - post back with any probs

Ciao
Avatar of dcgimo

ASKER

Okay, before I drive myself crazy...Since you both had the same concept I tried implementing apresto's suggestion into my search page, but it does not seem to be doing anything, an error is not occuring and my results are not displaying.  The result part is not disaplying at all, not even to say "no results" when it does not find anything, so I dont even think it is making it to that part of the code.  I am very new to this, so I might just be implementing the code at the wrong parts, this is how I modified it...

<%
     'check to make sure the user is logged in
'If Session("blnValidUser") <> True Then Response.Redirect("Login.asp")

Dim strURL      ' The URL of this page
Dim strConnect  ' ADO connection
Dim rstSearch   ' ADO recordset
Dim strDBPath  
Dim SQL              
Dim strSearch   ' The text being searched for
Dim ObjCmd
Set ObjCmd = Server.createobject("ADODB.command")
Dim StrPin, StrFname, StrLname, StrStreenNum, StrStreetName

strURL = Request.ServerVariables("URL")
strSearch = Request.QueryString("search")
strPin = Request.QueryString("Pin")
strFname= Request.QueryString("Firstname")
strLname = Request.QueryString("Lastname")
strStreetNum = Request.QueryString("StreetNumber")
strStreetName = Request.QueryString("StreetName")

%>
<form action="<%= strURL %>" method="get">
<input name="PIN" value="<%= strSearch %>" size="20" /><BR>
<input name="FirstName" value="<%= strSearch %>" size="20" /><BR>
<input name="LastName" value="<%= strSearch %>" size="20" /><BR>
<input name="StreetNumber" value="<%= strSearch %>" size="20" /><BR>
<input name="StreetName" value="<%= strSearch %>" size="20" /><BR>
<input type="submit" value='Search'  />
</form>

<%
If strSearch <> "" Then
strDBPath = Server.MapPath("database.mdb")

Set strConnect = Server.CreateObject("ADODB.Connection")
strConnect.Open "Provider=SQLOLEDB; DRIVER=SQLServer; SERVER=; UID=; PWD=; DATABASE=;"
'will change this to connection file when development is done
                   
'SQL = "exec searchdata_proc '" & Replace(strSearch, "'", "''") & "%' "
'Set rstSearch = strConnect.Execute(SQL)


objCmd.Activeconnection = Strconnect
objCmd.CommandText = "Searchdata_proc(" & StrPin & ", " & StrFname & ", " & StrLname & ", " & strStreetNum & ", " & strStreetName & ")"
objCmd.CommandType = 04
objCmd.CommandTimeout = 300
SET rstSearch = objCmd.execute
%>

<%
    response.write("<form name='displayresult' method='POST' action='results.asp'>" & vbcrlf)
    response.write("<select name='id'>" & vbcrlf)
if  rstSearch.eof then
    response.write("<option value=''>No Results</option>" & vbcrlf)
else
    response.write("<option value=''><u>Parcel Number, Owner, Address</option></u>" & vbcrlf)
    do while not rstSearch.eof
        response.write(vbtab & "<option value='" & rstSearch("parcel_number") & "'>" & rstSearch("parcel_number") & " , " & rstSearch("last_name") &  ", "  &rstSearch("first_name") & " , " & rstSearch("house_number") & " " & rstSearch("house_number_suffix") & " " & rstSearch("prefix_directional") & " " & rstSearch("Street_name") & " " & rstSearch("street_suffix") & " " & rstSearch("post_directional") & ", " & rstSearch("community_name") & "</option>" & vbcrlf)
        rstSearch.movenext
    loop
end if
response.write("</select>" & vbcrlf)
response.write("<input type='submit' value='Display Results' />" & vbcrlf)
response.write("</form>" & vbcrlf)
%>
   
<%
     rstSearch.Close
     Set rstSearch = Nothing
     strConnect.Close
     Set strConnect = Nothing
End If

%>
</BODY>
</HTML>

There are a few things to try:

1) instead of passing variables, try executing the command object with literal values to see if that works
2) modify your code like this for testing:

objCmd.Activeconnection = Strconnect
objCmd.CommandText = "Searchdata_proc(" & StrPin & ", " & StrFname & ", " & StrLname & ", " & strStreetNum & ", " & strStreetName & ")"
response.write objCmd.CommandText
response.end

objCmd.CommandType = 04
What error is it giving you?

If it isnt giving anything, right click on the asp page and click "view Source" scroll down to the bottom and it might say it in the source code
Good Call :o)
Avatar of dcgimo

ASKER

I'm sorry I got pulled away yesterday...

FtB- I tried executing the command object with literal values, and nothing seems to be happenning.  I alsi modified my code like you suggested, but no luck.

Apresto- Unfortunatly I'm not getting an error.  When I view the source,  this is all I see (the form)

<form action="/TaxQuery/noname1.asp" method="get">
<input name="parcel_number" value="" size="20" /><BR>
<input name="First_name" value="" size="20" /><BR>
<input name="Last_name" value="" size="20" /><BR>
<input name="HouseNum" value="" size="20" /><BR>
<input name="Street" value="" size="20" /><BR>
<input type="submit" value='Search'  />
</form>

</BODY>
</HTML>


Any other ideas I can test?
If the ASP search code is in the same page as the form change the form tag to this:

<form action="noname1.asp" method="get">

Assuming that this page is called Noname1.asp

When ftb suggested doing a

response.write objcmd.commandtext

This prints what is going into the stored procedure string in the asp page to the asp page, this is good for debuggingfor reference its this bit:

objCmd.Activeconnection = Strconnect
objCmd.CommandText = "Searchdata_proc(" & StrPin & ", " & StrFname & ", " & StrLname & ", " & strStreetNum & ", " & strStreetName & ")"
response.write objCmd.CommandText  '>>>This prints
response.end   '>>>Ths stops the page dead in itsa path, nothing else after this is executed
Avatar of dcgimo

ASKER

Your so quick!

Hmmm, nothing seems to be happenning.  Should it be writing what is going into the stored procedure in the actual page, or in the address bar?  I am not seeing anything on the page, but in the address bar I see...

http://gisweb/TaxQuery/noname1.asp?parcel_number=0101100004&First_name=Robert&Last_name=Mende&HouseNum=35820++&Street=PEARL+ST+

huum, strange, it should print this but with actual values:

"Searchdata_proc(" & StrPin & ", " & StrFname & ", " & StrLname & ", " & strStreetNum & ", " & strStreetName & ")"

Is the form submitting to itself, when you hit submit, where is the data being posted? Also are you doing any

response.redirect's?
The issue here is that if the command text does not print, then for certain, it won't execute.

If this doesn't work out soon, we should try modifying my code to meet your needs.

FtB
Avatar of dcgimo

ASKER

Yes, it is submitting to itself on submit, and displaying results in a dropdown on the same screen where the user can select the closest match and click another submit button where they are directed to a more detailed page about the record (results.asp).  The only response.redirect I have is to make sure the user is logged in...
If Session("blnValidUser") <> True Then Response.Redirect("Login.asp")
Avatar of dcgimo

ASKER

Ftb, I'd be willing to modify your code...but there are a few parts I am unclear about, one being the select statement and the other being the declaration of variables.  If I am calling a stored procedure (and therefore declaring the variables in the sp) and I am also doing the select statement in the sp, would I simply have to exec the stored procedure instead of the select and declaration parts of your code?
Right, so it would look like this:

Set objCommand = Server.CreateObject ("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Name of your stored procedure here"
objCommand.Parameters.Append objCommand.CreateParameter("@strShipRegion",adVarChar,adParamInput ,12,"SP")
objCommand.Parameters.Append objCommand.CreateParameter("@curFreight",adCurrency,adParamInput , ,50)
objCommand.Parameters.Append objCommand.CreateParameter("@intYear",adInteger,adParamInput , ,1997)
Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open objCommand,,3,3


FtB
Avatar of dcgimo

ASKER

Ftb- In the last... line objRS.Open objCommand,,3,3 can you interpret this(specifically the 3,3)?  I am getting an error on this line:  Procedure "sp name" expects parameter @strPIN which is not supplied.

Also, do you utilize a form to collect values from the user, or do you just pass them in the code?

Okay, lets step through the process:

1) you can pass the parameters via code or by using the request collection:

dim strPin
strPin = Request.form("strPin")
objCommand.Parameters.Append objCommand.CreateParameter("@strPin",adVarChar,adParamInput ,12,strPin)

or:

objCommand.Parameters.Append objCommand.CreateParameter("@strPin",adVarChar,adParamInput ,12,Request.form("strPin"))

will give you the same results.

2) the 3,3 sets the cursor and lock type

3) if you do not have the ADOVBS.inc file included in your page, then you will have to declare some constants like this:

Const adCmdStoredProc = &H0004
Const adParamInput = &H0001
Const adVarChar = 200
Const adCurrency = 6
Const adInteger = 3


Here is a list of the more common parameter types:


'---- DataTypeEnum Values ----
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205
Const adChapter = 136
Const adFileTime = 64
Const adDBFileTime = 137
Const adPropVariant = 138
Const adVarNumeric = 139

FtB
Avatar of dcgimo

ASKER

Okay, that makes sense.  I have changed the page slightly to request the parameter.  But, as soon as I load the page I get an error;  Procedure "sp name" expects parameter @strPIN which is not supplied.  I am not even getting a chance to enter any values, yet the stored procedure is trying to execute, and then failing because no parameters were provided.  Does anything jump out at you that might be causing this?

<%
Const adCmdStoredProc = &H0004
Const adParamInput = &H0001
Const adVarChar = 200
Const adCurrency = 6
Const adInteger = 3

Dim strDataPath, strConnectString, objConnection, objCommand, objRS,i
dim strPin
dim strFirstName
dim strLastName

strConnectString = "Provider=SQLOLEDB; DRIVER=SQLServer; SERVER=; UID=; PWD=; DATABASE=;"

if not IsObject("ojbConnection") then
     set objConnection=Server.CreateObject("ADODB.Connection")
     objConnection.ConnectionTimeout = 15
     objConnection.CommandTimeout =  10
     objConnection.Mode = 3 'adModeReadWrite
     if objConnection.state = 0 then
          objConnection.Open strConnectString
     end if
end if

Set objCommand = Server.CreateObject ("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = "search"

strPin = Request.form("strPin")
objCommand.Parameters.Append objCommand.CreateParameter("@strPin",adVarChar,adParamInput ,10,strPin)
strFirstName = Request.form("strFirstName")
objCommand.Parameters.Append objCommand.CreateParameter("@strFirstName",adVarChar,adParamInput ,30,strFirstName)
strLastName = Request.form("strLastName")
objCommand.Parameters.Append objCommand.CreateParameter("@strLastName",adVarChar,adParamInput ,30,strLastName)

Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open objCommand,,3,3


%>
</HEAD>
<BODY>
<%
Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
Do while not  objRS.EOF
     Response.Write("<TR>")
     for i=0 to objRS.Fields.count-1
          Response.Write("<TD>" & objRS(i).Value & "</TD>")
     next
     Response.Write("</TR>")
     objRS.MoveNext
Loop
Response.Write("</Table>")
Response.write("Number of records returned: " & objRS.RecordCount)
%>
</BODY>
<%
set objCommand = Nothing
objRS.Close
Set objRS = Nothing
objConnection.Close
set objConnection = Nothing
%>

</HTML>
Now that is very odd. If I look at your SP, these are the parameters that you need in this order:

@strPIN varchar(10),
@strFirstName varchar(30),
@strLastName varchar(30),
@strHouseNum varchar(10),
@strStreet varchar(30)

and it does look like you are passing them. I wonder why this is being an issue.....

I don't suppose that you DBMS is case sensitive?

strPin as opposed to strPIN

Also, let's make sure that you are getting form values---please put this at the top of your page:

For each objField in Request.Form
   response.write(objField & ": " & Request.Form(objField) & "<BR>")
next
response.end

This will tell us what is being passed.

FtB


Avatar of dcgimo

ASKER

Okay, I checked case sensitivity first and that was not it.  When I added...

For each objField in Request.Form
   response.write(objField & ": " & Request.Form(objField) & "<BR>")
next
response.end

to the top of the page & reloaded, nothing appears, no errors, just a blank page.
Okay, this is great! That means that there are no values being passed to the page. Please verify that the form that posts to this page uses the POST method and that all of the fields are well formed and fall within the form tags.

FtB
Avatar of dcgimo

ASKER

My form page should just be as simple as collecting values and clicking submit, right?  Like so...

<%
     'check to make sure the user is logged in
'If Session("blnValidUser") <> True Then Response.Redirect("Login.asp")

dim strPIN
dim strFirstName
dim strLastName

                   
%>
<form action="noname2.asp" method="POST">
<input name="PIN" value="<%= strPIN %>" size="20" /><BR>
<input name="First_Name" value="<%= strFirstName %>" size="20" /><BR>
<input name="Last_Name" value="<%= strLastName %>" size="20" /><BR>
<input type="submit" value='Search'  />
</form>

</BODY>
</HTML>
Okay good. Now, the code to call the sproc is on noname2.asp? Also, is this form on a different page or do you have the form and the processing code all on the same page?

FtB
Avatar of dcgimo

ASKER

Yes, the stored procedure is on noname2.asp (dont worry, this is not my normal naming convention!). The form is on a different page right now, but ideally in the end I would like one page.

I think I might have something here...When I enter data into the form page and click submit, it is now opening noname2.asp and displaying the data I entered into the form.  The only problem is that it is displaying anything I type in, whether it is a real record in my data or not.
Okay, let's regroup.

Fill out your form and then press submit. At the very top of noname2.asp, place the following code:

For each objField in Request.Form
   response.write(objField & ": " & Request.Form(objField) & "<BR>")
next
response.end


What this should do is give you a list of the field names on the form, and what values you posted. Please post the result here, and then we can move on to the next step.

FtB
Avatar of dcgimo

ASKER

Okay, done.  I filled out my form with 0101100001, Robert, Smith and clicked submit.  Then I was directed to noname2.asp and this is what appeared...

PIN: 0101100001
First_Name: Robert
Last_Name: Smith

So, that worked.  Problem is that there is no record, the last name should be Mende.  So, it seems it is gathering my data from the form and displaying it in noname2.asp, but my stored procedure is not executing because if it was then I would have gotten no results.
That is okay. At this point here, the response.end stops the database code from ever executing.

Hang on a minute...

FtB
Avatar of dcgimo

ASKER

Ah, of course it does!
Okay, go ahead and remove these lines from the top of your page--we don't need them any more.

For each objField in Request.Form
   response.write(objField & ": " & Request.Form(objField) & "<BR>")
next
response.end

Now, this little test told us that you have values passed with the following field names:

PIN  First_Name  Last_Name

So, we need to modify these lines:

strPin = Request.form("strPin")
objCommand.Parameters.Append objCommand.CreateParameter("@strPin",adVarChar,adParamInput ,10,strPin)
strFirstName = Request.form("strFirstName")
objCommand.Parameters.Append objCommand.CreateParameter("@strFirstName",adVarChar,adParamInput ,30,strFirstName)
strLastName = Request.form("strLastName")
objCommand.Parameters.Append objCommand.CreateParameter("@strLastName",adVarChar,adParamInput ,30,strLastName)

to look like this:

strPin = Request.form("PIN")
objCommand.Parameters.Append objCommand.CreateParameter("@strPin",adVarChar,adParamInput ,10,strPin)
strFirstName = Request.form("First_Name")
objCommand.Parameters.Append objCommand.CreateParameter("@strFirstName",adVarChar,adParamInput ,30,strFirstName)
strLastName = Request.form("Last_Name")
objCommand.Parameters.Append objCommand.CreateParameter("@strLastName",adVarChar,adParamInput ,30,strLastName)

Do you see why?

FtB
Avatar of dcgimo

ASKER

Oh yes, of course!
When I changed that I am back to the error:

Procedure 'sp name' expects parameter '@strPIN', which was not supplied

Wouldn't the above code change send PIN through as the parameter @strPIN?
Okay, this shouldn't matter, but let's try (I matched the case of the parameters here to that in your sproc):

strPin = Request.form("PIN")
objCommand.Parameters.Append objCommand.CreateParameter("@strPIN",adVarChar,adParamInput ,10,strPin)
strFirstName = Request.form("First_Name")
objCommand.Parameters.Append objCommand.CreateParameter("@strFirstName",adVarChar,adParamInput ,30,strFirstName)
strLastName = Request.form("Last_Name")
objCommand.Parameters.Append objCommand.CreateParameter("@strLastName",adVarChar,adParamInput ,30,strLastName)


Also, I am curious about this:

WHERE
parcel_number = @strPIN or
first_name LIKE + '%' + @strFirstName +'%' and
last_name LIKE + '%' + @strLastName +'%' and
HouseNum LIKE + '%' + @strHouseNum +'%' and
street LIKE + '%' + @strStreet +'%'
GO

If strPin is a string rather than a numeric value, don't you need to have delimiters around it like the rest of your parameters?

FtB
Avatar of dcgimo

ASKER

I noticed the case change too and changed it like you did just in case, but no luck.

Actually strPIN is a unique 10 digit number, it is an identification number for a piece of property.  But, the company who designed the database declared the data type as varchar, but I want the user to type in the exact number.  The other fields are a mess (name and address related fields)... sometimes first_name is in with the last_name, there are '&''s in the fields, there are middle initials in the last name field, house numbers in the street name field, etc.
So do you have leading or trailing 0's on the strPIN if it is less than 10 digits long? Also, I think that you may need to specify the exact length for the other parameters (by using len(strFirstName) for example).

FtB

Avatar of dcgimo

ASKER

Yes, some of the strPIN do have leading or ending zeros, but that is part of the 10 digit number (0101100001), but if I try running the sp in sql query analyzer, and pass it parameters, it works great.

When you say I should specify the length of the other paramteres, where do you mean, in the code?
Yes, like this:

objCommand.Parameters.Append objCommand.CreateParameter("@strFirstName",adVarChar,adParamInput ,len(strFirstName),strFirstName)

In any event, I have asked ACPerkins to join the thread as he is much better at this than I am. He will be able to take a look at your sproc and my command code and set things straigth in short order...

FtB
Avatar of dcgimo

ASKER

Okay, thanks for all your time today Ftb!  I feel like I'm missing something in the stored procedure, but I just don't see anything wrong with it and it runs fine on its own.  I'll be heading home shortly, so I'll try some more testing tomorrow,  once again, thank you!
Without reading too much into this thread and assuming that you the stored procedure runs correctly in SQL Query Analyzer with a given set of parameters than I would have to conclude that something is amiss in the ASP code.  It seems that you are not passing all the parameters (there are 5) and they do not allow for default values.  Byt the way, the name of the parameters is not important (unless of course you are setting the NamedParameters property) the order on the other hand, is important.

So to save my sanity (what little I have left), can you post the following:
1. Your current version of the Stored Procedure.
2. Your current version of your ASP code.
3. Any errors or invalid results.
4. What is the desired result.

Thanks,
I will look at it tonight when I get home.
Avatar of dcgimo

ASKER

Thanks for looking into this, ACPerkins.  

1.  I actually simplified my stored procedure to try and get just a few fields to work instead of all of them at once, it is now only asking for 3 paramaters, but otherwise it is essentially the same as before, here it is:

CREATE PROCEDURE Search
@strPIN varchar (10),
@strFirstName varchar(50),
@strLastName varchar(50)
as
SELECT first_name,  last_name, parcel_number, housenum, street,
house_number, house_number_suffix, prefix_directional, street_name, street_suffix, post_directional, community_name
from SearchView
WHERE
parcel_number = @strPIN and
first_name LIKE + '%' + @strFirstName +'%' and
last_name LIKE + '%' + @strLastName +'%'
GO

2.  I have 2 asp pages, though I would in the end like one page...

Page 1:  ModSearch.asp  (form where user enters data and clicks submit)

<%
     'check to make sure the user is logged in
'If Session("blnValidUser") <> True Then Response.Redirect("Login.asp")

dim strPIN
dim strFirstName
dim strLastName
           
%>
<form action="noname2.asp" method="POST">
<input name="PIN" value="<%= strPIN %>" size="20" /><BR>
<input name="First_Name" value="<%= strFirstName %>" size="20" /><BR>
<input name="Last_Name" value="<%= strLastName %>" size="20" /><BR>
<input type="submit" value='Search'  />
</form>

</BODY>
</HTML>


Page 2:  The search results page:  NoName2.asp




<%

Const adCmdStoredProc = &H0004
Const adParamInput = &H0001
Const adVarChar = 200
Const adCurrency = 6
Const adInteger = 3



Dim strDataPath, strConnectString, objConnection, objCommand, objRS,i
dim strPIN
dim strFirstName
dim strLastName

strConnectString = "Provider=SQLOLEDB; DRIVER=SQLServer; SERVER=; UID=; PWD=; DATABASE=;"

if not IsObject("ojbConnection") then
     set objConnection=Server.CreateObject("ADODB.Connection")
     objConnection.ConnectionTimeout = 15
     objConnection.CommandTimeout =  10
     objConnection.Mode = 3 'adModeReadWrite
     if objConnection.state = 0 then
          objConnection.Open strConnectString
     end if
end if

Set objCommand = Server.CreateObject ("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = "search"

strPin = Request.form("PIN")
objCommand.Parameters.Append objCommand.CreateParameter("@strPIN",adVarChar,adParamInput ,10, strPin)
strFirstName = Request.form("First_Name")
objCommand.Parameters.Append objCommand.CreateParameter("@strFirstName",adVarChar,adParamInput ,30,strFirstName)
strLastName = Request.form("Last_Name")
objCommand.Parameters.Append objCommand.CreateParameter("@strLastName",adVarChar,adParamInput ,30,strLastName)


Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open objCommand,,3,3


%>
</HEAD>
<BODY>
<%
Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
Do while not  objRS.EOF
     Response.Write("<TR>")
     for i=0 to objRS.Fields.count-1
          Response.Write("<TD>" & objRS(i).Value & "</TD>")
     next
     Response.Write("</TR>")
     objRS.MoveNext
Loop
Response.Write("</Table>")
Response.write("Number of records returned: " & objRS.RecordCount)
%>
</BODY>
<%
set objCommand = Nothing
objRS.Close
Set objRS = Nothing
objConnection.Close
set objConnection = Nothing
%>

</HTML>

3.  When I enter the data into the form (in ModSearch.asp) and click submit, I am directed to noname2.asp, and the following error occurs:
         
             Procedure 'Search' expects parameter '@strPIN', which was not supplied.

4.  My desired result was to have a search page where a user can enter either a PIN, name or address, click submit and have the results returned in a list where they would select the exact or closest match from a drop-down and click another submit button which directs them to a detailed results page.  I have this concept working, but it is only for one paramater, not several.  My working page is what I posted in my initial post.  I knew the stored procedure would need to be modified to accept many paramaters, so I modified  it (again in the first post), and that I would need to add more text boxes to accept more parameters, but I could not get the version with more paramaters to function.


ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It looks like I copied your code (and the LIKE error as well!) the stored procedure should be (removed the + after LIKE):

CREATE PROCEDURE Search
     @strPIN varchar (10),
     @strFirstName varchar(50),
     @strLastName varchar(50)

As

SET NOCOUNT ON

Select     @strFirstName = '%' + @strFirstName +'%' ,
     @strLastName = '%' + @strLastName +'%'

Select     first_name,  
     last_name,
     parcel_number,
     housenum,
     street,
     house_number,
     house_number_suffix,
     prefix_directional,
     street_name,
     street_suffix,
     post_directional,
     community_name
From     SearchView
Where     parcel_number = @strPIN
     And first_name LIKE @strFirstName
     And last_name LIKE @strLastName

GO
@ACPerkins:

A question about the parameters please:

 .Parameters.Append .CreateParameter("@strFirstName", adVarChar, adParamInput, 30, Request.form("First_Name"))

If I pass "Anthony" as the first name, will the 30 work or should it be 7?

FtB
Avatar of dcgimo

ASKER

acperkins- I added that missing line to the code and that worked, and the stored proc. is so much more efficient now!  Thank you so much!  I do have a follow up question...I cannot get your simplified version of the code to work, I am getting a error...

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

on this line:     .CommandType = adCmdStoredProc
But, I dont see why that would cause such an error. Any ideas?

FtB- I tested out your code (which is now working great!!!) with "Anthony", and kept it set at 30 and it worked just fine.  I think because in the stored procedure it is searching that field for anything that may contain that name.  In my data, in the first_name field one of my records is :  'Robert L & Dixie L'  (I know, it's terrible data), but if I enter 'Dixie', it finds it, or if I enter 'Robert' it finds it, or even if I enter 'L' it will find it.  I think that's what you were asking...
>>If I pass "Anthony" as the first name, will the 30 work or should it be 7?<<
Since you are creating the parameter (describing all its properties: data type, direction, length, value and optionally precision and scale) it should match the argument(s) in the stored procedure.  So to answer your question it should be 30 (though it probably works either way)

>>I am getting a error...<<
You probably have not declared (or included the ADOVBS.inc file) the adCmdStoredProc constant. Try changing this:

.CommandType = adCmdStoredProc

To:
.CommandType = 4
>>So to answer your question it should be 30 (though it probably works either way)<<

Thanks Anthony, that is good to know!

FtB
Avatar of dcgimo

ASKER

acperkins, your right, I did not include the ADOVBS.inc file, and FtB just explained that to me yesterday.

Thank both of you for all your help.  Everything is working great now!  Now being somewhat new here, what is the etiquite with points?
Take a look at this:

https://www.experts-exchange.com/help.jsp#hi69

However, I am fine if you would like to award all of the points to ACPerkins for setting this straight.

FtB
What I meant was that you should either include all the ADO contants (namely adCmdStoredProc, adVarChar and adParamInput) or use literal constants.
Avatar of dcgimo

ASKER

acperkins- sorry, I didn't make that clear, but I understood about the contants, FtB pointed that out to me yesterday.

I'll split the points since FtB got me on the right track and acperkins fixed the problem.  Thanks again to both of you!
>>I am fine if you would like to award all of the points to ACPerkins for setting this straight.<<
I am not.  I simply reiterated what had already been stated.  At the very least split the points as suggested by fritz in the link he posted.
Too late, again :)
You are very welcome and good luck with your code.


(Anthony, thank you once again for the lesson!)

FtB