Database + Text File Comparison

Results 1 to 2 of 2

Thread: Database + Text File Comparison

  1. #1
    Join Date
    Dec 1969

    Default Database + Text File Comparison

    Since I am still fairly new to ASP, I am hoping that someone could maybe write me a little bit of script to do this or point me in the right direction, I know exactly what needs to be done, I just can&#039t write it in ASP. Here it is in simple terms.<BR><BR>I have a list of names in a text file, each name on a seperate line:<BR><BR>Robert<BR>James<BR>John<BR>Matt<BR><B R>I now need to check to see if these names, one at a time, are in the database table called "online".<BR><BR>Eg. If "robert" is present in NickName field of "online" - response.write "Online&#062;Robert" else response.Write "Offline&#062;Robert"<BR>End If<BR><BR>... then I need to repeat that for every person (loop).<BR><BR>Problem is I don&#039t know how to read lines in text files, and I don&#039t know how to move onto the next line or anything really...any thoughts?

  2. #2
    Marty Guest

    Default RE: Database + Text File Comparison

    What you need is the FileSystemObject. There is a lot of info about how to use it at under VBScript &#062; Documentation.<BR><BR>This code should accomplish your desired result:<BR>&#039I am assuming Online is a DSN named Online <BR>&#039Open the connection and recordset<BR>set conn=server.createobject("adodb.connection")<BR>co "DSN=Online"<BR>set rs=conn.execute("select nickname from tblNames")<BR><BR>set fso=server.createobject("scripting.FileSystemObjec t")<BR>set namefile=fso.opentextfile("c:
    ames.txt")<BR>strName=namefile.readline<BR>do until namefile.AtEndOfStream<BR> booNameMatch=false<BR> rs.movefirst<BR> do until rs.eof or booNameMatch<BR> if strName=rs("NickName") then<BR> booNameMatch=True<BR> end if<BR> rs.movenext<BR> loop<BR> if booNameMatch then<BR> response.write "Online&#062;" & strName <BR> else<BR> response.write "Offline&#062;" & strName <BR> end if<BR> strName=namefile.readline<BR>loop<BR>.<BR>.<BR>Hop e this helps. While I was coding, I couldn&#039t help but notice how inefficient this whole process is. Maybe you need to add a boolean field to your database called "online". <BR>Good luck.<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