Domanda

I have to do a calculation to an integer value in classic asp, but i keep getting "type mismatch" error on this line: X = tempID + 1

this is my code:

 Set TheRS = Conn.Execute("select top 1 xx from W_TABLE order by IDX desc")
   tempID = TheRS("xx")
   X = tempID + 1
   TheRS.Close
   Set TheRS = nothing

tempX is of type "User-defined Type"... i'm assuming that's why it wont let me add 1 to it... how can i make this happen?

È stato utile?

Soluzione 4

got it working by changing the select.

select top 1 xx+1 from W_TABLE order by IDX desc

thanks everyone!

Altri suggerimenti

I've had this problem with numeric/decimal columns. ADO returns the value as a Decimal type, but VBScript doesn't really support the Decimal type. About the only thing you can do with a variable that contains a Decimal type value is convert it using CInt, CDbl, or any of the other conversion functions. My guess is that if you were to inspect the value of VarType(tempID), you would see 14, which corresponds to vbDecimal.

To work around this, you should convert the value using CDbl (or CInt if you don't care about the decimal portion).

  1. Check if the recordset is end of file first. (If TheRS.Eof Then)
  2. It seems to me "xx", whatever that is, isn't actually an integer. Are you sure your query is returning a numerical answer?
  3. Chances are that's why you can't add 1 to it. Try cast it as an integer first: X = CInt(tempID) + 1
  4. Response.Write(tempID) before adding 1 and see what value it has

Not to be rude but that code is indecipherable! W_TABLE? IDX? xx? These are all terrible variable and schema names. I sincerely hope that you have just sanitized your real, appropriately named variables for more abstract, confusing ones.

If you don't want to bother what your database query returns this should do the trick:

X = CInt("0" & tempID) + 1
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top