PDA

View Full Version : Take a look at this 'ere line o' code...



Erin Salmon
05-12-2002, 06:00 PM
Hi Guys...

To those who are familiar with ASP, perhaps you could enlighten me as to what is wrong with this code...

CPU = Connect.Execute("SELECT CPUName FROM CPU WHERE CPUPerformance="&CPUVal"")

CPUVal is a number between 1 and 5 determining the performance of a CPU.

This executes just fine when the paqe loads, unless I try to then display the value 'CPU' (As defined by the line above), when it gives me an error.

Replacing the ..."&CPUVal"")... with the number 1 does not help, although this piece of SQL works fine as a query in Access.

I'm sure I've had this problem before, but I can't remember how I solved it, and the same lines of code are executing happily on other pages.

So what's the solution guys?

Ta :)

Erin

Erin Salmon
05-12-2002, 06:01 PM
Hi again,

Before you tell me I'm a complete retard, I should correct that line of code:

CPU = Connect.Execute("SELECT CPUName FROM CPU WHERE CPUPerformance="&CPUVal&"")

There.

:)

Erin

Heather P
05-12-2002, 06:33 PM
Quote marks? Used them in one place but not the other. Doesn't this mean you are saying is this "String" a number instead of is this number a number?

Erin Salmon
05-12-2002, 07:08 PM
Hi,

Not sure I grasped your meaning there... I tried with single and double quotation marks, as I know that makes a difference in Access, but it just fed me more errors.

I have had trouble before with variables containing numbers, which think they contain text. However, I'm pretty certain that is not the case.

Is it possible to state when creating a variable that it is to be treated as a number? I recall something like:

Dim Variable1 as Number

But I've never managed to get it going, I just feed things from one variable to another as needed. Things pulled from a database always appear in the approriate form (text/number) as corresponding with the column in the database.

Anyway, can you explain what you meant, or re-write the line of code as you think it should read.

Cheers,

Erin

Dolby Digital
05-12-2002, 08:32 PM
ASP (not ASP.NET) is a typeless language so you can't go:
Dim var1 as integer
Dim var1 is the best you can do so its a variant.

What datatype is the field in the WHERE clause? I always use single quotes around 'strings' as this seems to keep more databases happy.

Erin Salmon
05-12-2002, 09:24 PM
Hi,

It seems that despite the error message there was nothing wrong with this line of code. However, when I went to access the information created by that line of code, it had problems.

I solved it by creating the Variable "CPU2", and defining it:

CPU2 = CPU("CPUName")

Also, if I don't want to manipulate the name of the CPU, I just print:

Response.Write CPU("CPUName")

Simple really! :)

There is probably a better way of doing this however, as this requires two sets of variablse to be created, where only one should really be needed. This script already has over a hundred variables, and it's the first time I've had to put notes in my code to explain what it's doing.

Cheers,

Erin

Heather P
05-12-2002, 09:37 PM
Hi,

Threw the answer up before then departed to cook dinner.

CPU = Connect.Execute("SELECT CPUName FROM CPU WHERE CPUPerformance="&CPUVal&"")

should probably read:
CPU = Connect.Execute("SELECT CPUName FROM CPU WHERE CPUPerformance="&CPUVal&)

If you get stuck on SELECT statements - run up a quick table in Access then use the QBE to write the query for you. Copy and paste.

Erin Salmon
05-12-2002, 10:58 PM
Hi,

The line of code was in fact correct! The funny business with the quote marks can be explained like this:

CPU = Connect.Execute("SELECT CPUName FROM CPU WHERE CPUPerformance='&CPUVal&'")

Notice that the double quotes surround the entire SQL statement (this is an ASP thing), and the single quotes surround the ASP variable (this is to break out of SQL, back into ASP).

The real problem lay about 250 lines further down (although the error pointed to that line) - Now that's gotta be confusing!

Me new site is very nearly ready, and this time, it is to be hosted on my own network. I'll give you a shout when it's all up and running so you can come and admire (pick holes in?) it.

:)

Erin