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

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))

8 1878
PsychoCoder
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
colol
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
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
colol
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
colol
8
Dear Rabbit,

can i do it like this --> str = "SELECT * FROM * WHERE (word = "& Replace(txt, "@txt", txt)&"
Aug 17 '12 #6
Rabbit
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
colol
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
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.