'syntax' question

Results 1 to 2 of 2

Thread: 'syntax' question

  1. #1
    Join Date
    Dec 1969

    Default 'syntax' question

    I&#039;ve been working on a few internal apps using an Access database and ASP forms. Everything&#039;s working fine, I was just wondering if I&#039;m putting my ASP pages together properly. For instance, there&#039;s this database with a multitude of tables and queries. To update something, I build a form with a bunch of drop-down boxes that are populated with results from a Select statement. What I&#039;m doing is open all seperate recordsets at the beginning of the script, such as:<BR>set Catrs = Server.CreateObject("ADODB.recordset")<BR>Catrs.Op en "Select * from t_category" , conn<BR>set Applrs = Server.CreateObject("ADODB.recordset")<BR>Applrs.O pen "Select tac_class from t_appl" , conn<BR>etc. (add 6 or 7 more of these)<BR>Then when building the update form, it&#039;ll be like:<BR>case "category" %&#062;<BR> &#060;select NAME="category"&#062;<BR> &#060;%while NOT Catrs.EOF%&#062; <BR> &#060;option value="&#060;%=Catrs("ID")%&#062;" <BR> &#060;%if (Catrs("category") = strSfield.value) then <BR> Response.write " SELECTED" <BR> end if<BR> %&#062;&#062;&#060;%=Catrs("category")%&#062;<BR > &#060;/option&#062;<BR> &#060;%Catrs.Movenext<BR> wend%&#062;<BR> &#060;/select&#062;<BR>And I do this for each of the recordsets I opened at the beginning.<BR>Is this a good way to do it? Is there a cleaner way?

  2. #2
    Join Date
    Dec 1969

    Default Not syntax...coding practice...

    "Syntax" simply means the GRAMMAR of the language. And obviously there is nothing wrong with either you SQL grammar or your VBS grammar or your code wouldn&#039;t work.<BR><BR>Anyway...<BR><BR>The answer to your question lies in this question: How *dynamic* are all these recordsets that you are using to build the drop down lists??<BR><BR>If the recordsets are only changed once a day (or week or or or), then why go get them from the DB for each "hit" of the page? Why not, instead, get them ONE TIME, put each into an Application variable (Application("Category") = ...), and then just grab them from there as you need them? Then, only when you actually *change* the contents of the table that affects that recordset do you go change the contents of the Application variable. Yes, I said *application*, not *session*, since all users share the same lists, I presume. <BR><BR>What form should you save them in, as app variables? Either as an array (and you can use ADODB.RecordSet.GetRows to convert the RS to an array easily!) or as a string (and see the ASPFAQs on how to convert an RS to a string using GetString in an effective manner). Whichever makes more sense to the various ways you will use the data. (String would be faster if you will *always* use the data to build the same &#060;SELECT&#062; lists, array is more flexible since it is really just another form of the raw data.)<BR><BR>Hokay?<BR><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