Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple code problem...

Status
Not open for further replies.

sladewilson

Programmer
Feb 14, 2002
90
US
What is wrong with this...

<%
Dim strProdCode
strProdCode = strCatCode &"-"& strBrandCode &"-"& strProdId
Response.Write (strProdCode)
%>

I want output that looks like this:

shoe-nike-2838
 
nothing wrong with it...are you sure all your other variables have correct values...why do u think it is not working...

-DNG
 
Not sure... here's the rest of the page...

Dim strBrandCode
objRst.Open "Select * FROM Brands WHERE brand = " & Session("Brand") & ";", objConnect
strBrandCode = objRst("brand_code")
objRst.Close

Dim strCatCode
objRst.Open "Select * FROM Categories WHERE category_name = " & Session("Category") & ";", objConnect
strCatCode = objRst("category_code")
objRst.Close

Dim strProdId
strProdId = Session("id")

Dim strProdCode
strProdCode = strCatCode &"-"& strBrandCode &"-"& strProdId


Response.Write (strProdCode)
 
put response.write statements to make sure that you are getting the correct values...

-DNG
 
I think my problem is in the WHERE statement(s)...

I'm trying to skin this cat a different way now...

When I do this I get the correct value.

strCategory = Session("Category")
Response.Write (strCategory)

So I know the Session is set correctly.

Now I try this and I get FROM clause errors...

objRst.Open "Select * FROM Categories WHERE category_name = (strCategory)"
Response.Write objRst("category_code")
objRst.Close

Any ideas?

 
you should something like this:

objRst.Open "Select * FROM Categories WHERE category_name = '"&strCategory)&"' "

-DNG
 
oops...have a typeo...

objRst.Open "Select * FROM Categories WHERE category_name = '"&strCategory&"' "

-DNG
 
Thank you so much.... where can I find a good reference of sql syntax?
 
also i noticed alot open/close recordsets, these tend to take more server overhead to use, try cutting your code down a little by :
( note less open/close cycles, uses one object and recycles it, also only pull the data you need, if you pull everything, you will be transmitting alot more data than is needed, slowing many things down. )

Code:
Set Con = server.createobject("adodb.connection")
con.open objConnect

Dim strBrandCode, strCatCode, strProdId, strProdCode

Set objRst = Con.Execute("Select top 1 brand_code FROM Brands WHERE brand = " & Session("Brand"))
If not objRst.eof then strBrandCode = objRst("brand_code") 

Set objRst = Con.Execute("Select top 1 category_code FROM Categories WHERE category_name = " & Session("Category"))
If not objRst.eof then strCatCode = objRst("category_code")

Set objRst = nothing
Con.Close
Set Con = nothing

strProdId = Session("id")

strProdCode = strCatCode &"-"& strBrandCode &"-"& strProdId

Response.Write (strProdCode)

as for no variable output, perchance you're not getting the values out of the db, perhaps mismatched brandname/brandcode etc.

another item to consider, perchance, when you assign the session"brand" you could also assign the session"brandid"


[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never inside the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top