Solved

Returning values from Stored Procedures using ASP/SQL

Posted on 2006-11-10
18
994 Views
Last Modified: 2012-06-27
Hi,
I am having extreme difficulty with my code. The error I am receiving is the following:
"Microsoft OLE DB Provider for SQL Server (0x80040E14)
Procedure or function PMS_FindAMAMember has too many arguments specified.
/param/AMA_Results.asp, line 39"
Line 39 pertains to the following line: adocmd.Execute
I am not sure why it would say. From my perspective, everything appears to fine.
What I need to do is get the results for the Primary, Secondary, FirstName, LastName, Address, State and Zip Code to be displayed from the the user selection.
I already have a form created where a user enters a firstname and lastname of a person and then the results should populate from the database for that specific firstname/lastname request.
Thank you for your help.


My Stored Procedure is as follows:
CREATE PROCEDURE PMS_FindAMAMember @LastName  VARCHAR(75), @FirstName VARCHAR(75)
AS
BEGIN
SELECT GoodME,
      primary_specialty_code as 'Primary',
      Secondary_Specialty_code as 'Secondary',
        first as 'FirstName',
      last as 'LastName',
      Primary_Address as 'Address',
      State as 'State',
      zip_hyphen as 'Postal Code'
FROM AMA
WHERE Last = @LastName AND First = @FirstName
END
GO

My ASP code is as follows:
<!-- #include file="adovbs.inc" -->

<%
      DIM strLastName, strFirstName
      strLastName = Request.Form("LastName")
      strFirstName = Request.Form("FirstName")
%>

<%
      Dim Connection
      Dim tempString
      Dim ConnectionString
      Dim Recordset
      Dim SQL
      Dim ofso
      Dim otmp

       Set ofso = Server.CreateObject("Scripting.FileSystemObject")
        Set otmp = ofso.OpenTextFile(Server.MapPath("config.ini"))
        tempString = otmp.ReadLine
        ConnectionString=Mid(tempString, 19, Len(tempString) - 19)


      Dim objconn,objRS,strSQL, adocmd
      Set objconn = Server.CreateObject("ADODB.Connection")
      objconn.Open (ConnectionString)

      objRS = Server.CreateObject("ADODB.Recordset")
      Set adocmd = Server.CreateObject("ADODB.Command")
      adocmd.CommandText = "PMS_FindAMAMember"
      adocmd.CommandType = adCmdStoredProc

      adocmd.activeConnection = objconn
      adocmd.Parameters.Append adocmd.CreateParameter("@LastName",adVarChar, adParamInput, 75)
      adocmd.Parameters.Append adocmd.CreateParameter("@FirstName",adVarChar, adParamInput, 75)
      adocmd.Parameters.Append adocmd.CreateParameter("State",adChar, adParamReturnValue, 10)
      adocmd.Parameters("@LastName") = Request.Form("LastName")
      adocmd.Parameters("@FirstName") = Request.Form("FirstName")
      adocmd.Execute
      
%>

<HTML>
<HEAD><TITLE>Results</TITLE></HEAD>
<BODY>


<%
Response.Write adocmd("State")


'<% Response.Write("<b><center><u>RESULTS</u></center></b>") %>
<br>

      adocmd.Close
      objconn.Close
%>

</BODY>
</HTML>


0
Comment
Question by:pimpp1184
  • 10
  • 5
  • 2
  • +1
18 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
http://support.microsoft.com/kb/q164485/

     adocmd.activeConnection = objconn
     adocmd.Parameters.Append adocmd.CreateParameter("RETURN_VALUE",adInteger, adParamReturnValue)
     adocmd.Parameters.Append adocmd.CreateParameter("@LastName",adVarChar, adParamInput, 75)
     adocmd.Parameters.Append adocmd.CreateParameter("@FirstName",adVarChar, adParamInput, 75)
     adocmd.Parameters("@LastName") = Request.Form("LastName")
     adocmd.Parameters("@FirstName") = Request.Form("FirstName")
     adocmd.Execute
0
 

Author Comment

by:pimpp1184
Comment Utility
Thanks angelIII for your quick response.
I had actually checked out that webpage and pertained my code to the way that microsoft had stated it. But it still gives me the same error, regardless of me changing to the code to what you stated. I can't get the result to come up. I am trying to make the 'state' result come out with the code that I wrote but no luck. Any other suggestions? Thanks
0
 
LVL 6

Expert Comment

by:bigphuckinglizard
Comment Utility
    adocmd.activeConnection = objconn
     adocmd.Parameters.Append adocmd.CreateParameter("@LastName",adVarChar, adParamInput, 75)
     adocmd.Parameters.Append adocmd.CreateParameter("@FirstName",adVarChar, adParamInput, 75)
     adocmd.Parameters("@LastName") = Request.Form("LastName")
     adocmd.Parameters("@FirstName") = Request.Form("FirstName")
     Dim SqlReader as SqlDataReader = adocmd.ExecuteReader()
While SqlReader.Read
Response.Write(SQLReader.Item("Firstname") & SQLReader.Item("Lastname"))
EndWhile

is correct - you need to make sure the number of parameters in the vb code match the number of parameters in the stored procedure and if you're returning a rowset you need a sqlreader to store the results, not a return parameter.
0
 

Author Comment

by:pimpp1184
Comment Utility
Hi. Thanks for your response. I entered the code exactly how you stated it and I got the following error:
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/param/AMA_Results.asp, line 43, column 14
Dim SqlReader as SqlDataReader = adocmd.ExecuteReader()
----------------------------------------------------------^
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
bigphuckinglizard's suggestion is vb.net (asp.net) syntax/objects... here we have to do vbscript (asp)

now, as you procedure does not define the return value at all, you should remove the parameter definition of the return value:

     >adocmd.Parameters.Append adocmd.CreateParameter("RETURN_VALUE",adInteger, adParamReturnValue)

also, the line
Response.Write adocmd("State")

gives no sense in your case...
0
 
LVL 5

Expert Comment

by:prajapati84
Comment Utility
Replace ur code with this one, hope this will work for u.

     adocmd.activeConnection = objconn
     adocmd.Parameters.Append adocmd.CreateParameter("Last",adVarChar, adParamInput, 75,Request.Form("LastName"))
     adocmd.Parameters.Append adocmd.CreateParameter("First",adVarChar, adParamInput, 75,Request.Form("FirstName"))
     adocmd.Parameters.Append adocmd.CreateParameter("State",adChar, adParamReturnValue, 10)
     adocmd.Execute

Regards,
Mukesh
0
 

Author Comment

by:pimpp1184
Comment Utility
Thanks for your quick responses. I still what prajapti84 said and i got the following error:
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Procedure or function PMS_FindAMAMember has too many arguments specified.
/param/AMA_Results.asp, line 41

Don't know what else to do from here. I'll keep researching but its getting quite tedious.
Thanks.
0
 

Author Comment

by:pimpp1184
Comment Utility
angelIII, if I were to remove those 2 procedures. How would I be able to return the results that I want returned such as Address, State, Zip Code, etc.? Any suggestions?
Thanks
0
 

Author Comment

by:pimpp1184
Comment Utility
I have raised the point value for this question. I need assistance with this question asap. Thanks
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Expert Comment

by:bigphuckinglizard
Comment Utility
apologies, thought i was in the asp.net forum ;) you need to get rid of the state parameter as it's not defined in the stored procedure. you also need a recordset to contain the results:

     adocmd.activeConnection = objconn
     adocmd.Parameters.Append adocmd.CreateParameter("@LastName",adVarChar, adParamInput, 75)
     adocmd.Parameters.Append adocmd.CreateParameter("@FirstName",adVarChar, adParamInput, 75)
     adocmd.Parameters("@LastName") = Request.Form("LastName")
     adocmd.Parameters("@FirstName") = Request.Form("FirstName")
     set results = Server.CreateObject("ADODB.Recordset")
     results.open adocmd, objconn
     do while not results.eof
         response.write results("first") & results("last") & results("state")
     loop
0
 

Author Comment

by:pimpp1184
Comment Utility
bigphuckinglizard , Thank you for your response. But sadly I had tried the code stated above but I got the following error and am totally confused as to why I am getting it.
# Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'Open'
/param/AMA_Results.asp, line 42
This code pertains to line: results.open adocmd, objconn

Thanks hopefully you can assist me in this matter as this it the only thing that is holding me back to completing the rest of my project. Thanks again.
0
 
LVL 6

Expert Comment

by:bigphuckinglizard
Comment Utility
weird, matches code i have working here... try

adocmd.activeConnection = objconn
     adocmd.Parameters.Append adocmd.CreateParameter("@LastName",adVarChar, adParamInput, 75)
     adocmd.Parameters.Append adocmd.CreateParameter("@FirstName",adVarChar, adParamInput, 75)
     adocmd.Parameters("@LastName") = Request.Form("LastName")
     adocmd.Parameters("@FirstName") = Request.Form("FirstName")
     set results = Server.CreateObject("ADODB.Recordset")
     results = adocmd.Execute
     do while not results.eof
         response.write results("first") & results("last") & results("state")
     loop
0
 

Author Comment

by:pimpp1184
Comment Utility
bigphuckinglizard, Thanks for the incredibly quick reply.
Here is the error I am getting now.
Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'eof'
/param/AMA_Results.asp, line 43

and the Code I am using is the following:
      objRS = Server.CreateObject("ADODB.Recordset")
      adocmd.activeConnection = objconn
       adocmd.Parameters.Append adocmd.CreateParameter("@LastName",adVarChar, adParamInput, 75)
       adocmd.Parameters.Append adocmd.CreateParameter("@FirstName",adVarChar, adParamInput, 75)
       adocmd.Parameters("@LastName") = Request.Form("LastName")
       adocmd.Parameters("@FirstName") = Request.Form("FirstName")
       objRS = adocmd.Execute
         do while not objrs.eof
               response.write objRS("state")
         loop

and the error line is the following: do while not objrs.eof

I will try to research the error a bit more while I wait for your input on this problem. Thanks
0
 

Author Comment

by:pimpp1184
Comment Utility
Alright I figured out that problem. i had to put "set" in front of objRS = adocmd.Execute
Then I got another error:
Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'Close'
/param/AMA_Results.asp, line 47
The line this is referring to is: adocmd.Close
I commented the line out and the code worked perfectly. I actually had to change the do while not loop to
         if not objrs.eof then
               response.write objRS("state")
         end if

With the do while not loop, the code gave me a error stating the the code was timed out for some reason but I changed it to if not loop and it worked perfectly.
But I was wondering if I need the adocmd.close command because I thought closing the adodb.command is necessay?
Any suggestions? Thanks.
I am going to go through the code and make sure everything is working fine before I give you the points for your help.
Thanks
0
 
LVL 6

Accepted Solution

by:
bigphuckinglizard earned 450 total points
Comment Utility
ah- forgot the line to make it loop through the recordset rather than going over and over the same row...

     do while not objrs.eof
             response.write objRS("state")
             objRS.MoveNext
        loop
0
 

Author Comment

by:pimpp1184
Comment Utility
Thanks, which statement is better to use the do while not loop or the if not loop?
Also do you have suggestions on adocmd.close as to why I am getting the error:
Object doesn't support this property or method: 'Close'
Thanks
0
 
LVL 6

Expert Comment

by:bigphuckinglizard
Comment Utility
the do while shoud be used normally, you can use the if method if you are sure you will only get one result.

you need to close the connection object, not the command ie. it should be objconn.close - you shouldn't have to worry too much about this as the conenction will be closed automatically when the page finishes executing.
0
 

Author Comment

by:pimpp1184
Comment Utility
Thanks for your help. I'm on the right track with the project. Crossing fingers that I dont' cross into more problems. If I do, i will be back. Thanks again.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now