Solved

ASP - Type Mismatch

Posted on 2014-01-22
7
455 Views
Last Modified: 2014-01-23
To start, I only have 1 record in my DB (brand new) and none of the fields are blank.

If i change productname (which is a text field in the DB) to price (which is currency in the DB) then this code works.  If I leave productname then I get:

Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "TestProduct"]'
/triplels/index.asp, line 12

Ideas why I am getting this?

<%
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.Open "DSN=triplels"

strSQL = "SELECT (productname) "
strSQL = strSQL & "FROM inventory"
rs.Open strSQL, conn

WHILE NOT rs.EOF

IF rs("productname") = 2 THEN
    productname = productname & "<option selected value=" & rs("productname") & ">" & rs("productname") & "</option>"
ELSE
    productname = productname & "<option value=" & rs("productname") & ">" & rs("productname") & "</option>"
END IF

rs.MoveNext

WEND

rs.Close
conn.Close

%>

Open in new window

0
Comment
Question by:bschwarting
[X]
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
7 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 300 total points
ID: 39801456
If productname is a string then you cannot compare it against a number

IF rs("productname") = 2 THEN

and productname sounds counter intuitive if you are storing a number in the field
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 150 total points
ID: 39801626
that is because a currency data type in a database is numerical, thats why it'll work if the database type is currency. if the database field does indeed contain the string "2" then you could do:

IF CInt( rs("productname") ) = 2 THEN

that'll convert the value to an integer data type. If the value is not an integer, it'll cause an error.

I do agree though, productname indicates a string to me, and not an integer value.

I also noticed in your loop you're missing some single quotes around your value attribute. it should be (i added spaces for readability, you should take them out):

WHILE NOT rs.EOF

IF rs("productname") = 2 THEN
    productname = productname & "<option selected value=' " & rs("productname") & ">" ' & rs("productname") & "</option>"
ELSE
    productname = productname & "<option value='  " & rs("productname") & " '>" & rs("productname") & "</option>"
END IF

rs.MoveNext

WEND

Open in new window

0
 
LVL 53

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 50 total points
ID: 39801885
Instead of converting to an integer, I think it is a little better to covert everything to a string and that way you will avoid any error when there are things like nulls or blanks.

cStr(rs("productname")) = "2" THEN

On another note, is there a reason you are using a DSN connection?  DSN-Less connections are faster and safer.  Here is something more current http://blogs.office.com/2011/04/08/power-tip-improve-the-security-of-database-connections/ but if you read up at 4guys there are plenty of articles dating back to 1999 on the benefits.
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!

 
LVL 1

Author Comment

by:bschwarting
ID: 39803380
Guys, thanks for all this, it worked great.  I totally missed the =2 part.  When you pointed that out, it fixed my 1st issue.

I love the ASP portion of this site, best part of experts-exchange IMO.  You guys are awesome.

The only other issue I have is when it populates my drop down list, I lose the "value" to post the one I end up selecting.  So when I select the first in the list, then submit the form, the value is blank.

Ideas why this is happening?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39803400
glad you got it working :)

hard to say why, as we don't have the full code for the select box html. make sure you have a  NAME attribute on it, and also make sure you implemented my code for adding single quotes around the VALUE attribute in the options (taking out the single space that I added for readability). If all tha checks out, post your code so we can have a look.
0
 
LVL 1

Author Comment

by:bschwarting
ID: 39803555
Found my issue!  I had the wrong name in my area where the <select> tags were:

<!-- DROP DOWN FROM DATABASE -->
Product Name<br>
<select size="1" name="productname">
<%=productname%>
</select>
<!-- DROP DOWN FROM DATABASE -->

Open in new window

0
 
LVL 1

Author Closing Comment

by:bschwarting
ID: 39803559
Thanks!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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