Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Using Update..


Message #1 by "Eric Robbins" <erobbins@w...> on Thu, 30 May 2002 22:27:45
I need to update a database with information from a folder I have.  The 
files in the folder are named with an id field in the db.

Caveat, I have more files than records in the db.

I need to update the fields with info based on what is in the db with the 
criteria being called from the folder.   

Currently, if my db does not contain a field it will not update and will 
stop, giving me a token error.

The db I am using is an AS400 using SQL language.
*****************
<%
Dim dbMyWeb,dbMyWeb2
Dim rsMyWeb,rsMyWeb2
Dim TheSql,TheSql2

'Open SQL
Set dbMyWeb = Server.CreateObject("ADODB.Connection")
dbMyWeb.Open "DSN=AS400;UID=WEBREQUEST;PWD=PJG874FX;DBQ=WESTUSASYS;NAM=0;EX
TDYNAMIC=1;PKG=WESTUSASYS,1,0,1,0,0;"
Set rsMyWeb = Server.CreateObject("ADODB.Recordset")

	'Insert SQL
	Set dbMyWeb2 = Server.CreateObject("ADODB.Connection")
	dbMyWeb2.Open "DSN=AS400;UID=WEBREQUEST;PWD=PJG874FX;DBQ=WESTUSASYS
;NAM=0;EXTDYNAMIC=1;PKG=WESTUSASYS,1,0,1,0,0;"
	Set rsMyWeb2 = Server.CreateObject("ADODB.Recordset")
	TheSql = "SELECT * FROM WESTUSASYS.LISTFILE"
	rsMyWeb.Open TheSql, dbMyWeb, 3
'**************************

    sPhysicalPath = Server.Mappath("./PICTURE/")
    Set dct = CreateObject("Scripting.Dictionary")
    set fso = CreateObject("Scripting.FileSystemObject")
    set Folder = fso.GetFolder(sPhysicalPath)
    set SubFolders = Folder.SubFolders
    set FolderContents = Folder.Files

    For Each oFile In FolderContents
    
        sFileName = fso.GetBaseName(oFile)
        If dct.Exists(sFileName) Then
            dct(sFileName) = dct(sFileName) + 1
        Else
            dct.Add sFileName, 1
        End If
        
    Next
    
    Dim key

    For Each key In dct
	'Do While rsMyWeb("QMLS#")=key
	TheSql2 = "UPDATE WESTUSASYS.LISTFILE SET QPHOTO#='"  & CStr(dct
(key)) & "' WHERE QMLS#='" & key  & "'<BR>"
	Response.Write(TheSql2 &" SQL INSERT OK!<BR>") 
	dbMyWeb2.Execute TheSql2
	'Can't forget to move to the next record!
	'rsMyWeb.MoveNext

        'Response.Write "File " & key & " has " & CStr(dct(key)) & " 
images <BR>"
	'Response.Write "UPDATE tablename SET imagecount='"  & CStr(dct
(key)) & "' WHERE id='" & key  & "'<BR>"
	'Loop
    Next


rsMyweb.close

set rsMyWeb=nothing
Set dbMyWeb2=nothing
Set dbMyWeb=nothing
%>

  Return to Index