Type-casting does not work...weirdest problem ever

Results 1 to 2 of 2

Thread: Type-casting does not work...weirdest problem ever

  1. #1
    Join Date
    Dec 1969

    Default Type-casting does not work...weirdest problem ever

    I am using ASP SQL-statements to create RecordSets that satisfy certain conditions. I am using an Access database.<BR>Let&#039s say I have a certain value X that is submitted on page 1 through a &#060;INPUT NAME="X" TYPE="text"&#062;. It is passed to page 2 using the POST method. On Page 2 it is requested and put in a variable varX. This varX is then used in the SQL statement to select Firsnames of people who have a bigger value for varX.<BR><BR>Example Code Page 2:<BR><BR>Dim strQ,varX<BR>varX = Request.Form("X")<BR>strQ = "SELECT FirstName FROM Personal WHERE Rating &#062; " & varX<BR>objRS.Open strQ<BR><BR>Now the strange problem:<BR>When the &#039Rating&#039 field in my Access database is declared as type: Text ,then the query works.<BR>If I declare the &#039Rating&#039 field as type: Numerical, then it does not work. Even when the type is set to Integer and I use<BR>CInt(varX) to make varX of VarType Int, then still I get a type-mismatch error!<BR><BR>Is this some kind of strange MS-Access error? Is there something I can do about this. It is really weird. The variable is of type: Int. I checked this using VarType(varX)<BR>The field is set to Numerical, type Integer. So, they really are both Integer but I still get the Type-mismatch error!!<BR><BR>HELP

  2. #2
    Steve Cimino Guest

    Default RE: Type-casting does not work...weirdest problem

    What you want to do in this situation is make your db field a numeric data type (will provide faster lookups). You&#039re correctly not placing &#039 &#039 around the numeric data type, but you also need to convert varX to a number since request.form will return string data.<BR><BR>WHERE Rating &#062; " & CInt(varX)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts