Solved

"Application uses a value of the wrong type" Error

Posted on 2006-11-24
9
608 Views
Last Modified: 2008-01-09
The following is the code that I am using:
Stored Procedure (Partial code):

CREATE  PROCEDURE GetRespondentDemographics
      @Email nvarchar(75) = null,
      @Respondentid dec(19,0) = null

.......
 
My ASP Code:
<%
      Dim ConnectionString
      Dim ofso
      Dim otmp

        ConnectionString="Provider=SQLOLEDB;Data Source=TEST_W2K_SQL2K;Database=harrispoll;UID=paramtestuser;PWD=paramtestuser;Network Library=dbmssocn;"

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

    Set adocmd = Server.CreateObject("ADODB.Command")
    adocmd.CommandText = "GetRespondentDemographics"
    adocmd.CommandType = adCmdStoredProc
 
    objRS = Server.CreateObject("ADODB.Recordset")
    adocmd.activeConnection = objconn
    adocmd.Parameters.Append adocmd.CreateParameter("@Email",adVarChar, adParamInput, 75)
    adocmd.Parameters.Append adocmd.CreateParameter("@Respondentid",adDecimal, adParamInput, 19)
    adocmd.Parameters("@Respondentid").Precision = 19
    adocmd.Parameters("@Respondentid").NumericScale = 0
    adocmd.Parameters("@Email") = Request.Form("email")
    adocmd.Parameters("@Respondentid") = Request.Form("respondentid")
    set objRS = adocmd.Execute

Ok. I have 2 fields (RespondentID and Email). The user must select at least one of the fields even though both fields can be filled out. Now my problem is that when I only enter the respondentID, I am able to get the results back without a problem BUT when I only enter the email field, I get the following error:
"Error Type:
ADODB.Command (0x800A0D5D)
Application uses a value of the wrong type for the current operation.
/param/HPoll_email_respondent_results.asp, line 28"

The line this is referring to is: adocmd.Parameters("@Respondentid") = Request.Form("respondentid")
When I comment out this field and I go back and enter an email within the email field, the program executes and displays the results without a problem. I do not understand why I am getting this error. The line that it is referring to as incorrect appears correct from my point of view. Any suggestions as to why I might getting this error? Thanks
0
Comment
Question by:pimpp1184
  • 5
  • 3
9 Comments
 

Author Comment

by:pimpp1184
ID: 18016522
Any suggestions at all from anyone on this? Thanks
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18019569
Why are you using nvarchar in your stored proc?
Shouldn't you be using varchar?
0
 

Author Comment

by:pimpp1184
ID: 18021967
hclgroup,

That part of the code works perfectly. As I stated above, the email part of the code works fine. The problem exists only when I leave the "respondentid" field blank. If I were to comment out this line, adocmd.Parameters("@Respondentid") = Request.Form("respondentid") and run the program by entering some data in the email field, the program executes.
The program also executes when I have data in the 'respondentid' field. The problem only persists when the 'respondentid' is left empty.
Thanks for your help.
0
 
LVL 4

Accepted Solution

by:
hclgroup earned 100 total points
ID: 18022046
Oh, I see, I misread what you had written.

Then put an if statement and only add the respondentid parameter when respondentid is not blank (since the stored procedure defaults it to NULL)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:pimpp1184
ID: 18027390
Doh! I thought I had tried that. Alright well I created this if-then statement:
      if (Request.Form("respondentid") = "") then
            adocmd.Parameters.Append adocmd.CreateParameter("@Email",adVarChar, adParamInput, 75)
            adocmd.Parameters("@Email") = Request.Form("email")
            set objRS = adocmd.Execute
      else
            adocmd.Parameters.Append adocmd.CreateParameter("@Email",adVarChar, adParamInput, 75)
            adocmd.Parameters.Append adocmd.CreateParameter("@Respondentid",adDecimal, adParamInput, 19)
            adocmd.Parameters("@Respondentid").Precision = 19
            adocmd.Parameters("@Respondentid").NumericScale = 0
            adocmd.Parameters("@Email") = Request.Form("email")
            adocmd.Parameters("@Respondentid") = Request.Form("respondentid")
            set objRS = adocmd.Execute
      end if

It appears to be working fine at a certain extent. The problem I am having now is that if I were to enter both of the fields (Email and respondentid), it will not check to see if the email is in the correct email format (which it will do if ONLY the email field was filled out). Also, if both fields were filled out and the respondentid was the correct one but the email was incorrect, it will still show the results because the respondentid was filled out correctly thus returning the results.
I would like it so if both fields are filled out and if one of the fields are incorrect (as in that it won't match the database table), the output will show 'no results found'.
Am I making sense or not? Let me know if you got some suggestions. Thanks
0
 

Author Comment

by:pimpp1184
ID: 18029218
Alright I figured out what I was doing wrong BUT I have another question if you can assist me on it.
As you know I have two fields (Email and RespondentID). The user has the option of choosing either or but never both of them.
Is there a javascript code which will disable one field if the user decides to type in another field.
Ex: The user types in an E-mail, the RespondentID field box will be disabled in that the user will be Unable to type in anything in there; and vice versa.

I have found codes which disable and enable but not what I am looking for as stated above.
Any Help wil be appreciated. Thanks
0
 

Author Comment

by:pimpp1184
ID: 18031252
Nevermind I fugured it all.
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18036130
I object, since my last response answered his original question.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

15 Experts available now in Live!

Get 1:1 Help Now