dynamic Request collection

Results 1 to 2 of 2

Thread: dynamic Request collection

  1. #1
    Join Date
    Dec 1969

    Default dynamic Request collection

    I need to know if it is possible to create a list of name/value pairs as request objects when you will only know the request names via a database query prior to receiving the request?<BR><BR>To explain further, I have a db table containing an infinite number of items whose "TYPE" from the database makes them a part of the request collection (for all items whose type is "X" I will be looking for a value in the request whose NAME is the value of that record&#039;s NAME column in the db)<BR><BR>So I need to write a dynamic listing using that info. Something like:<BR><BR>FOR ALL ITEMS in the request collection<BR>item1 = request(item1)<BR><BR>then I will need to do an update of the db using these values.

  2. #2
    Join Date
    Dec 1969

    Default Read the docs on FOR EACH...

    ...but do *NOT* assign each to a uniquely named variable! Big mistake.<BR><BR>Why not just build the SQL UPDATE statement on the fly? Or use the ADO update methodology on the fly? Much simpler.<BR><BR>The one thing you *NEVER* want in VBScript (or *any* computer language, for that matter!) is a dynamically named variable. Honest. Trust me on this one!<BR><BR>You could do something like this:<BR><BR>&#060;%<BR>...<BR>SQL = "UPDATE Table"<BR>delim = " SET "<BR>For Each Item In Request.Form &#039; or Request.QueryString<BR>&nbsp; &nbsp; SQL = SQL & delim & item & "=&#039;" & Request.Form(item)<BR>&nbsp; &nbsp; delim = "," &#039; change delimiter so SET appears only once! comma thereafter<BR>Next<BR>SQL = SQL & " WHERE recid = ... "<BR>conn.Execute( SQL )<BR>%&#062;<BR><BR>You *might* want to *prefix* the names of the items to be selected via the FOR EACH loop with something, so that you can put *other* things on the form without interference. For example, let&#039;s say you prefix each of such names with "$". Then your code could become:<BR><BR>&#060;%<BR>...<BR>SQL = "UPDATE Table"<BR>delim = " SET "<BR>For Each Item In Request.Form &#039; or Request.QueryString<BR>&nbsp; &nbsp; If Left(item,1) = "$" Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; itemName = Mid(item,2) &#039; strip off the $<BR>&nbsp; &nbsp; &nbsp; &nbsp; SQL = SQL & delim & itemName & "=&#039;" & Request.Form(itemName)<BR>&nbsp; &nbsp; &nbsp; &nbsp; delim = "," &#039; change delimiter so SET appears only once! comma thereafter<BR>&nbsp; &nbsp; End If<BR>Next<BR>SQL = SQL & " WHERE recid = " & Request.Form("RecordID") &#039; note: no $ on this field name!<BR>conn.Execute( SQL )<BR>%&#062;<BR>

Posting Permissions

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