473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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 2084
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,516 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,516 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,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. Response.Write(Replace(strSQL, "@word", word))
Aug 22 '12 #9

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

Similar topics

5
by: test | last post by:
why does this code cause the "Parameter count does not match Parameter Value count" error.??? Dim arGetaffManageparms() As System.Data.SqlClient.SqlParameter = New...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
2
by: Christine | last post by:
I am struggling to learn to use Access almost on my own, and have written a query that needs to have a parameter. The query I wrote includes in the Criteria of the design view, under the column...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
2
by: lgo | last post by:
I have read several variations of this topic posted on this news group. However I was not able to find the answer for my problem. I am trying to build code (see below) to update a large single...
2
by: rg | last post by:
Hi all, I have query about passing a parameter from form to a query. My situation is as follows: I have a query that pulls up some data from a table, however there is a condition that must...
1
by: Gary | last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to int... Earlier in my code I was setting up my dataset... I add an int field like so... ...
0
by: Mike Wilmot | last post by:
In converting a page from ASP to ASPX, I am getting the error: BC30289: Statement cannot appear within a method body. End of method assumed. when running the code below. It has something to do...
1
by: yoursteveis | last post by:
Dear all, I have created a main report (for monthly purchase summary) and a sub report (for monthly sales summary). I have linked main report with a parameter query (i.e. purchasesummary1) and...
4
by: Steve Richter | last post by:
I have a C++ forms project that I am adding some unmanaged code to. I have a member function of the Form1 class that returns a String^ holding the text of the last win32 error. The code is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.