Calling Recordset

Results 1 to 2 of 2

Thread: Calling Recordset

  1. #1
    Join Date
    Dec 1969

    Default Calling Recordset

    Is:<BR><BR>If rs("fldProfileType") &#060;&#062; "B" Then<BR><BR>Just as good as:<BR><BR>ProType = rs("fldProfileType")<BR>If ProType &#060;&#062; "B" Then<BR><BR>I have never figured that out for some reason...<BR>I would try it but I am getting code that when I use it, it fails to load the page at all.<BR><BR>Any obvious errors in this code that would cause it to cease or do whatever it is doing behind the scenes?<BR><BR>sSql = "SELECT * FROM tblCMProData WHERE tblCMProData.fldUserId = &#039;" & asplID & "&#039;"<BR>Set rs = conn.Execute( sSql )<BR><BR>Dim ProType<BR><BR>If (rs.BOF and rs.EOF) Then<BR> Response.Redirect ""<BR>Else<BR><BR> ProType = rs("fldProfileType")<BR> If ProType &#060;&#062; "B" Then<BR> Response.Redirect ""<BR> Else<BR> Response.Redirect ""<BR> End If<BR>End If<BR>rs.Close<BR>

  2. #2
    Join Date
    Dec 1969

    Default Better title: IMPROVING PERFORMANCE

    *Any* time you access a "collection" (in any language, but especially in VBScript and JScript) it takes longer than if you used a simple variable.<BR><BR>What collections do we find in ASP?<BR><BR>Request.QueryString<BR>Request.Form<BR >Request.Cookies<BR>Session.Contents<BR>Applicatio n.Contents<BR>Scripting.Dictionary<BR>and, of course,<BR>ADODB.Recordset<BR><BR>[Yes, of course there are others! That&#039;s just a sampling!]<BR><BR>So doing<BR>&nbsp; &nbsp; RS("anyFieldName")<BR>requires the system to go to that collection and try to find the key/value pair in the collection where the key has the name you gave. And then it has to extract the value from the collection.<BR><BR>[Actually, it is *much* worse than that! The system *also* has to go through THREE levels of "default properties", since what you are *actually* after is RS.Field.Item("anyFieldName").Value and although you can leave off .Field, .Item, and .Value, the system still has to figure out what you meant and do them anyway!]<BR><BR>So...<BR><BR>The rule is simple: If you will *ever* use a member of a collection more than once, copy it to a variable and then use the variable!<BR><BR>&#060;%<BR>...<BR>Do Until RS.EOF<BR>&nbsp; &nbsp; temp = RS("someField")<BR>&nbsp; &nbsp; If temp &#060;&#062; "" Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write temp<BR>&nbsp; &nbsp; End If<BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>Notice that I *did* put the assignment to the temp variable *inside* the DO...LOOP! That&#039;s because the value of the key/value pair in the recordset changes each time through the loop. And VBS isn&#039;t clever enough (nor would you want it to be!) to track changes in the recordset from a value you copied out of it previously.<BR><BR>HAVING SAID ALL THAT...<BR><BR>In *this* particular case...Do *not* use the temp variable. Because the only thing you are going to do is *one time* check the value of that field, yes? So the copy to the temp is a waste of time (admittedly, a very very minor when in doubt go ahead and do it).<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