Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
I get a type mismatch, simple script.
Old 06-09-2008, 09:21 AM I get a type mismatch, simple script.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Code:
 
<script language="vbscript" runat="server">
CustID=Request.QueryString("CustID")
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; "& "Data Source=" & Server.MapPath("/Data/Orders.mdb")
Set OrderData=Server.CreateObject("ADODB.RecordSet")
OrderData.CursorType = 3
OrderData.CursorLocation = 3
OrderData.ActiveConnection = conn
OrderData.Open("Select OrderID From Orders where CustomerID='"+CustID+"'")
OrdID=OrderData.Fields("OrderID")
OrderData.Close
OrderData.Open("Select ProductID From Items where OrderID='"+OrdID+"'")
RespStr=OrderData.GetString
Response.Write(RespStr)
</script>
The highlighted line causes the error...

The table Orders contains 2 columns and 1 record

OrderId (autonumber)
50

CusomerID
856564321986757 (Sess. var, global.asa, type text, temp customer ID)

The table Items contains 2 columns and 4 records (both columns text)

OrderID
50
50
50
50

ProductId
7463547
9283745
9283547
0298083

The tables are related via OrderID.
This script is serverside ajax.

Last edited by Sleeping Troll; 06-09-2008 at 09:24 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-09-2008, 10:10 AM Re: I get a type mismatch, simple script.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
no such thing as "serverside ajax"

and the FULL error message is?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-09-2008, 10:20 AM Re: I get a type mismatch, simple script.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Quote:
Microsoft VBscript runtime error '800a000d'
Type mismatch: string:"Select ProductID"
GetItems.asp, line 12
You are so picky Chris, guess that makes you a programmer.
It is an ASP script called by a javascript xmlhttp object (AJAX), don't think that has anything to do with problem... but?
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-09-2008, 06:14 PM Re: I get a type mismatch, simple script.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Maybe it appears picky, but it is important, especially when programming to have the correct information.

the problem could be one several things. best guess would be has OrdID returned with a value or is it NULL?

You should be using some error handling in there, especially when dealing with database retrieval and data passed in request collections.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-09-2008, 07:19 PM Re: I get a type mismatch, simple script.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
OrderID returns a number... cstr(OrderID) did the trick. thx.
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-09-2008, 07:26 PM Re: I get a type mismatch, simple script.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Here's the problem: You're using PLUS signs to concatenate strings instead of AMPERSAND signs.

Code:
OrderData.Open("Select ProductID From Items where OrderID='" & OrdID & "'")
In VBScript, the ampersand is used for string concatenation. When you use a plus, it tries to "literally" add the parameters, resulting in a type mismatch (since you're adding a number to a string).

CStr() will bypass the error as you figured out (by making both arguments strings), but the correct way is to just use ampersands for string concatenation anywhere you are writing vbscript. (Jscript uses + just like java and c++).

Also, it'd probably be better to remove the single quotes from the SELECT statement as well, since OrderID is a numeric field. The single quotes means you pass SQL a string, which it then has to convert back to a number to compare it to the OrderID field. Every millisecond saved is a millisecond faster that your page loads!

I would write it like this:
Code:
OrderData.Open("Select ProductID From Items where OrderID=" & OrdID)
__________________
~nyef

Please login or register to view this content. Registration is FREE

Last edited by nyef; 06-09-2008 at 07:30 PM..
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-10-2008, 02:00 AM Re: I get a type mismatch, simple script.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Hey Thx, I think you solved my next post too!

Nope, but it did clean up the OrderId script! thx again, perhaps you can be as helpful with the next one?

Last edited by Sleeping Troll; 06-10-2008 at 02:18 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I get a type mismatch, simple script.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49512 seconds with 12 queries