Solved

ASP - Type Mismatch

Posted on 2014-01-22
7
451 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
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 32

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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 32

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

25 Experts available now in Live!

Get 1:1 Help Now