By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,164 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,164 IT Pros & Developers. It's quick & easy.

sql statement cannot display parameter value

P: 8
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
  2.  
  3.    'collect values
  4.    word=Request.QueryString("word")
  5.  
  6. end if    
  7.  
  8.     'open connection to db
  9.     Set cn = Server.CreateObject("ADODB.Connection")
  10.     ConnStr = "..."
  11.     cn.Open(ConnStr)
  12.  
  13.     Set cmd = Server.CreateObject("ADODB.command")
  14.     Set rs = Server.CreateObject("ADODB.recordset") 
  15.     Set cmd.ActiveConnection = cn
  16.  
  17.     'statement
  18.     strSQL = "SELECT * FROM *WHERE (write = @word)"
  19.  
  20.     'assign to parameter
  21.     cmd.CommandText = strSQL
  22.  
  23.     'assign the value to the statement
  24.     cmd.Parameters.Append cmd.CreateParameter("@word", 200, 1, 20, word)
  25.  
  26.  
  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))

Share this Question
Share on Google+
8 Replies


PsychoCoder
Expert Mod 100+
P: 465
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

P: 8
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

Rabbit
Expert Mod 10K+
P: 12,369
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

P: 8
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

P: 8
Dear Rabbit,

can i do it like this --> str = "SELECT * FROM * WHERE (word = "& Replace(txt, "@txt", txt)&"
Aug 17 '12 #6

Rabbit
Expert Mod 10K+
P: 12,369
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

P: 8
Dear Rabbit,

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

Regards, Noor Atikah
Aug 22 '12 #8

Rabbit
Expert Mod 10K+
P: 12,369
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.