?
Solved

ASP - Type Mismatch

Posted on 2014-01-22
7
Medium Priority
?
458 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 1200 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 600 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 200 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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

801 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