468,544 Members | 1,815 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

sql statement cannot display parameter value

Hello, i am trying to view an sql statement with parameter values attach to it but somehow when i try to display it, Response.Write(), it is not showing the values but only the variable that is suppose to be switch to the values. Please help me, today is my deadline!! This is my code

Expand|Select|Wrap|Line Numbers
  1.  Dim x, ConnStr, str, cn, cmd, rs, strSQL
  3.    'collect values
  4.    word=Request.QueryString("word")
  6. end if    
  8.     'open connection to db
  9.     Set cn = Server.CreateObject("ADODB.Connection")
  10.     ConnStr = "..."
  11.     cn.Open(ConnStr)
  13.     Set cmd = Server.CreateObject("ADODB.command")
  14.     Set rs = Server.CreateObject("ADODB.recordset") 
  15.     Set cmd.ActiveConnection = cn
  17.     'statement
  18.     strSQL = "SELECT * FROM *WHERE (write = @word)"
  20.     'assign to parameter
  21.     cmd.CommandText = strSQL
  23.     'assign the value to the statement
  24.     cmd.Parameters.Append cmd.CreateParameter("@word", 200, 1, 20, word)
  27.     cmd.CommandText = strSQL
  28.     Response.Write(strSQL)
  29.     Set CurrentRecordSet = cmd.Execute() 
Aug 17 '12 #1

✓ answered by Rabbit

Expand|Select|Wrap|Line Numbers
  1. Response.Write(Replace(strSQL, "@word", word))

8 1878
465 Expert Mod 256MB
This query isnt a valid query:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM *WHERE (write = @word)"
Try with a valid sql statement like

Expand|Select|Wrap|Line Numbers
  1. SELECT * from TableName WHERE write = @word
Change 'TableName' to your table name.

NOTE: It's bad practice to use a
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM Table
query (unless you're accessing every column in the table)
Aug 17 '12 #2
the Request.String is link to words type by user. I am suppose to display the word type with the sql statement. not the value from db and the * represent the name of the table, i cannot show you the name as its confidential
Aug 17 '12 #3
12,513 Expert Mod 8TB
You're printing the strSQL variable so obviously it's only going to show what you put in there. You've done nothing to the string itself to replace the value in the string. If you want to replace the parameter name with the value, then you need to use the replace function to replace the variable name with the value before you print it out.
Aug 17 '12 #4
I'm sorry but i am very new to ASP thats why i'm not sure. can u show me how to use the replace function to replace the variable name with the value before it is print it out.
Aug 17 '12 #5
Dear Rabbit,

can i do it like this --> str = "SELECT * FROM * WHERE (word = "& Replace(txt, "@txt", txt)&"
Aug 17 '12 #6
12,513 Expert Mod 8TB
You don't want to change what you're passing to your database. You just want to change it before you print it.
Aug 17 '12 #7
Dear Rabbit,

can u please show me how, i really don't know how to do?

Regards, Noor Atikah
Aug 22 '12 #8
12,513 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. Response.Write(Replace(strSQL, "@word", word))
Aug 22 '12 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by test | last post: by
2 posts views Thread by Christine | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.