Print Page | Close Window

How to filter some data out of a database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=2862
Printed Date: 29 March 2026 at 10:15am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: How to filter some data out of a database
Posted By: eagle00789
Subject: How to filter some data out of a database
Date Posted: 20 May 2003 at 3:42am

I have a database containing ALL the links of my webpage. I want to create a menu out of this. That menu is working but there are some links that doesn't has to be in the menu. i can check this thru a special field in the database. if it is empty, then that link doesn't has to be in the menu, but i dont know how to filter. Below is the code for the database. i left out a lot of code for creating the menu. see the red comment in the code below to see the things that do and don't work. If possible, i need a quick answer.

Greetings Chris

---- menu.asp ----

Dim DataConn, cmdDC, rsDC
Dim Item
Dim iFieldCount, iLoopVar
Dim strLTorGT, iCriteria, strSortBy, strOrder
Dim sRequestIP

' Get request information
sRequestIP=Request.ServerVariables("REMOTE_ADDR")

' Set general variables
FoundRecordCount=0
'sDataSource = "d:\desktop\Webpagina gravenrode\links.mdb"
sDataSource = "c:\inetpub\wwwroot\links.mdb" ' Local Path to Database
BackgroundColor="FFFFFF"
RecordFound=0

' Create and establish data connection
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.ConnectionTimeout = 15
DataConn.CommandTimeout = 30

'Access connection code
DataConn.Open "DBQ=" & sDataSource & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;", "username", "password"


' Create and link command object to data connection then set attributes and SQL query
Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConn
cmdDC.CommandText = "SELECT * FROM Links"
cmdDC.CommandType = 1

' Create recordset
Set rsDC = Server.CreateObject("ADODB.Recordset")
' Opening record set with a forward-only cursor (the 0) and in read-only mode (the 1)
rsDC.Open cmdDC, , 1, 1

' Hier komt nu de loop om het menu in te lezen
    txtStream.WriteLine "//begin of database lookup"
    rsDC.MoveFirst
    Do while not rsDC.EOF 
    'this doesn't work why??
    If rsDC.fields("Menu_Location") = "" then
        rsDC.Movenext
    Else
 'this does work
 txtStream.WriteLine "Menu" & rsDC.fields("Menu_Location") & "=new Array(""" & rsDC.fields("LinkDescription") & """,""" & rsDC.fields("LinkUrl")& ""","",0,20,110);"
    End If
    rsDC.Movenext
    loop
    txtStream.WriteLine "//end of database lookup"
' Dit is het einde van de loop om het menu in te lezen

' Close Data Access Objects
rsDC.Close
Set rsDC = Nothing
Set cmdDC = Nothing
DataConn.Close
Set DataConn = Nothing

---- end menu.asp ----



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here



Replies:
Posted By: ljamal
Date Posted: 20 May 2003 at 10:56am
It may not work because the field is NULL and not ""
The best way to filter out these unwanted links is with your SQL statement.
you could use
SELECT * FROM Links where len(Menu_Location)>0

With your current code even if it did work the way you wish, it could potential cause an error because you could be moving 2 rows in the record set without checking if you are at the end of the recordset.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: michael
Date Posted: 20 May 2003 at 11:16am
I would check if it is not null like
SELECT whatever from table where field IS NOT NULL

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: eagle00789
Date Posted: 20 May 2003 at 12:40pm
i got it to work by using the following SQLstring:
SELECT Links.* FROM Links WHERE (((Links.Menu_Location) Is Not Null)) ORDER BY Links.Menu_Location;

-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net