Solved

Returning values from Stored Procedures using ASP/SQL

Posted on 2006-11-10
18
1,004 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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17914961
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
ID: 17915219
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
ID: 17915451
    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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pimpp1184
ID: 17916749
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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17918266
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
ID: 17919989
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
ID: 17922502
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
ID: 17923001
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
ID: 17926424
I have raised the point value for this question. I need assistance with this question asap. Thanks
0
 
LVL 6

Expert Comment

by:bigphuckinglizard
ID: 17928890
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
ID: 17929585
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
ID: 17929641
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
ID: 17929802
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
ID: 17929972
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
ID: 17929984
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
ID: 17930051
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
ID: 17930070
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
ID: 17931088
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

685 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