type mismatch requesting querystring

admin

Administrator
Staff member
Hi all,

The following code is giving me a 'type mismatch' error even though the field properties in the form and database are the same. Any ideas how i can around this?

If Request.form("spec") <> "" Then
sql1 = " SELECT * FROM specialists " & _
" WHERE_spu_id = " & TRIM(Request.form("spec"))
End If

Thanx in advanceYour title says Querystring, but your code is requesting from a Form. First, it is crucial that you understand that values from the Form are different from values in the Querystring. Form values come from values in input types on a page like text, hidden, radio, etc... Querystring values on the other hand are values concatenated onto the URL in the address bar.

With that said, I would say that it is your database throwing the error. First there is an _ between WHERE and spu_id that doesn't need to be there. Also what data type is spu_id, if it is a number, then you are good, but if it is a string then you need to surround it with a ' for example 'My String'This code work in my site.

Try like this dude:

Dim RsForm
RsForm = Request.form("spec") ' This should be the value of WHERE_spu_id field

If RsForm <> "" Then
sql1 = " SELECT * FROM specialists WHERE_spu_id = " + Replace(RsForm, "'", "''") + ""
End If

Note: + sign is the same as & sign

Dexter
Visit My ASP Code Bank (<!-- m --><a class="postlink" href="http://www.ex-designz.net/codemanager/default.asp">http://www.ex-designz.net/codemanager/default.asp</a><!-- m -->)Originally posted by dexterz

Note: + sign is the same as & sign


umm...no it is not.

When ASP encounters a + is assumes it is going to be performing a mathmatical operation. So if you are using + to concatenate your strings you are 1) slowing down the concatenation and 2) not ensuring that you are going to be getting the correct output. For example if you were to concatenate "1" + "1", it is quite possible the result could return 2 instead of "11". It is completely subjective on what the code feels like doing.

My point is that you should NEVER use + to concatenate your strings always &Both Ryan and Dexter are both sorta right....

+ can be used to concantenate strings in ClASP.
HOWEVER, it's best to use & to avoid errors.

Let's take, for example, the following statement....

response.Write(ubound(arrString) & " - ubound for my array")

....this code will work fine everytime and so will this

response.Write(cstr(ubound(arrString)) + " - ubound for my array")

.....BUT, the following will NOT....

response.Write(ubound(arrString) + " - ubound for my array")


The reason....
the ubound statement returns a number value. If ClASP sees a '+' following a number value it immediately assumes the mathematical function and when the second value isn't numerical, it throws an error. If ClASP sees a string preceeding a '+' then it will assume that the next value is also a string.

& always concats strings and, basically, does a cstr() around any value that it uses - that is why it is the safer of the two for everyday use.

ANYHEW, wood, did the problem resolve yet?I would like to add that its not a good thing to concatenate strings in a loop, as it requires that the string be re-allocated everytime it has an appended value.

VB calculates the lenght of both strings then allocates enough memory to handle it then uses C API underneathe to copy it using memcpy function. Its slow.... and also so is object creation.No, not having any luck with this guys. The code is part of an advanced search form which works fine until i start trying to search on tables that use joins.Can you upload the files so that we can attempt to help you more.okAnd the search form.........objrs.open sqlstring, sql1, objconn, 3, 3


there is an error. You have 2 sql strings

objRs.Open sql,conn,adOpenDynamic,adLockOptimisticOk, it is definately a data type problem after reading several similar threads. These are the two lines causing the problems:

" WHERE [Personnel].p_id = [specialists].[p_id] " & _
" AND_[specialists].spu_id = " & Cint(Request.form("spec"))

The error is: 'Syntax error (missing operator) in query expression'

However, i have written a response.write line after the sql and the correct 'id' is being pulled thru.Why do you have the underscore after AND?Sorry ignore that.

sqlstring = " SELECT Personnel.*, specialists.spu_id " & _
" FROM Personnel, specialists " & _
" WHERE Personnel.p_id = specialists.p_id " & _
" AND specialists.spu_id = " & CInt(request.form("spec"))
End If
response.write request.form("spec")

The response.write statement works fine and is pulling thru the correct value so its just a case of ensuring that the form field is a number datatype as is the database field.

thanx in advance
 
Back
Top