Variable Syntax

Results 1 to 3 of 3

Thread: Variable Syntax

  1. #1
    Jimmie7 Guest

    Default Variable Syntax

    I have a general variable question:<BR><BR>I am setting a variable to a field retrieved from a database using a recordset. The line is:<BR><BR>VarTemp=RS.Fields("Name")<BR><BR>While I have the recordset open in my asp page, everything works fine. I can Response.Write(VarTemp) (the "Name") to my html page, and do a number of other things. However, as soon as I close the recordset, I want to be able to Response.Redirect this variable (VarTemp) to another page. Unfortunately, I cannot do this while the recordset is open, and because of this, the variable VarTemp is no longer set to a valid recordset field when I Response.Redirect (since its looking for a field called "Name" in a non-existant recordset). <BR><BR>What is the syntax for defining a string variable to the value found in RS.Fields("Name"), NOT defining it to the recordset field itself. I want to be able to pass the "Name" to another asp page. Thanks for any help you guys can give me.

  2. #2
    Join Date
    Dec 1969

    Default RE: Variable Syntax

    The code you show *should* do what you want.<BR><BR>When you do<BR><BR>&#060;%<BR>Set fld = RS("fieldname")<BR>or<BR>Set fld = RS.Fields("fieldname")<BR>%&#062;<BR><BR>*THEN* the fld variable is a reference to the FIELD object.<BR><BR>But when you leave out the SET keyword and do<BR><BR>&#060;%<BR>str = RS("fieldname")<BR>or <BR>str = RS.Fields("fieldname")<BR>%&#062;<BR><BR>you are *supposed* to be assigning the field value to the "str" variable.<BR><BR>Were you possibly not showing us your actual code? Were you possibly using SET?<BR><BR>In any case, if you want to be paranoid about it, you can do:<BR><BR>&#060;%<BR>str = RS.Fields("fieldname").Value<BR>%&#062;<BR><BR>*th at* is guaranteed to give you the value as a string.<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default Not quite sure...

    I understand your problem but here goes...<BR><BR>varTemp = rst("fieldname")<BR><BR>...<BR><BR>rst.Close<BR><B R>varRedirect = "page2.asp?name=" & varTemp<BR><BR>Response.Redirect varRedirect<BR><BR><BR>That should work...<BR><BR>Jerry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts