sql statement cannot display parameter value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colol
    New Member
    • Aug 2012
    • 8

    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

    Code:
     Dim x, ConnStr, str, cn, cmd, rs, strSQL
       
       'collect values
       word=Request.QueryString("word")
    	
    end if	
        
    	'open connection to db
    	Set cn = Server.CreateObject("ADODB.Connection")
    	ConnStr = "..."
    	cn.Open(ConnStr)
    	
    	Set cmd = Server.CreateObject("ADODB.command")
    	Set rs = Server.CreateObject("ADODB.recordset") 
    	Set cmd.ActiveConnection = cn
    
    	'statement
    	strSQL = "SELECT * FROM *WHERE (write = @word)"
        
    	'assign to parameter
    	cmd.CommandText = strSQL
    	
    	'assign the value to the statement
    	cmd.Parameters.Append cmd.CreateParameter("@word", 200, 1, 20, word)
    	
    	
        cmd.CommandText = strSQL
    	Response.Write(strSQL)
        Set CurrentRecordSet = cmd.Execute()
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    This query isnt a valid query:

    Code:
    strSQL = "SELECT * FROM *WHERE (write = @word)"
    Try with a valid sql statement like

    Code:
    SELECT * from [I]TableName [/I]WHERE write = @word
    Change 'TableName' to your table name.

    NOTE: It's bad practice to use a
    Code:
    SELECT * FROM Table
    query (unless you're accessing every column in the table)
    Last edited by PsychoCoder; Aug 17 '12, 04:17 AM.

    Comment

    • colol
      New Member
      • Aug 2012
      • 8

      #3
      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

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        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.

        Comment

        • colol
          New Member
          • Aug 2012
          • 8

          #5
          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.

          Comment

          • colol
            New Member
            • Aug 2012
            • 8

            #6
            Dear Rabbit,

            can i do it like this --> str = "SELECT * FROM * WHERE (word = "& Replace(txt, "@txt", txt)&"
            Last edited by zmbd; Aug 21 '12, 05:15 AM. Reason: added code tags -z

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              You don't want to change what you're passing to your database. You just want to change it before you print it.

              Comment

              • colol
                New Member
                • Aug 2012
                • 8

                #8
                Dear Rabbit,

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

                Regards, Noor Atikah

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  Code:
                  Response.Write(Replace(strSQL, "@word", word))

                  Comment

                  Working...