|
 |
access_asp thread: A database updating question...(using Rs.Update)
Message #1 by "Mircea Goia" <mircea@c...> on Sun, 28 Jul 2002 22:57:07
|
|
Hi,
I have a table (in Access 2000) which (among others) has these columns:
Path_1, File_1, Path_2, File_2 ,Path_3, File_3.
And I have a script which uploads three files to the disk.
After uploading the files to the disk I want to write in the database the
path to every file and every file name.
I want that in the field "Path_1" to have the path to the file number 1
and in the field "File_1" to have the name of the file number 1.
And so on...
I use Rs.Update method:
~~~~~~~
rstLog.Fields("Path_1") = PathtoFile
rstLog.Fields("File_1") = FileName
rstLog.Fields("Path_2") = PathtoFile
rstLog.Fields("File_2") = FileName
rstLog.Fields("Path_3") = PathtoFile
rstLog.Fields("File_3") = FileName
rstLog.Update
~~~~~~~~~~
This Updating statement is inside of a Do while....Loop statement which
looks like this:
~~~~~~~~~
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
countloop = 0
Do While lngCurrentEnd > 0
......... among some other code here is also the Updating code
above .......
lngCurrentBegin = lngCurrentEnd
lngCurrentEnd = instr(lngCurrentBegin + 9 ,strDataWhole,strBoundry) - 1
'Prevents infinate loop.
countloop = countloop + 1
if countloop = 100 Then
Response.Write "looping 100 times.Terminating script !"
if rstLog.State then rstLog.close
Response.End
End if
loop
~~~~~~~~~~~
But only the details of the last file uploaded to the disk is entered in
the database !
What I have to change in the Updating statement above to accomplish this?
Thanks,
Mircea
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 29 Jul 2002 12:48:47 +1000
|
|
Where is the code where you put the values into the recordset?
Are you calling .AddNew within each loop?
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Mircea Goia" <mircea@c...>
Subject: [access_asp] A database updating question...(using Rs.Update)
: Hi,
:
: I have a table (in Access 2000) which (among others) has these columns:
: Path_1, File_1, Path_2, File_2 ,Path_3, File_3.
:
: And I have a script which uploads three files to the disk.
: After uploading the files to the disk I want to write in the database the
: path to every file and every file name.
:
: I want that in the field "Path_1" to have the path to the file number 1
: and in the field "File_1" to have the name of the file number 1.
: And so on...
:
: I use Rs.Update method:
: ~~~~~~~
: rstLog.Fields("Path_1") = PathtoFile
: rstLog.Fields("File_1") = FileName
: rstLog.Fields("Path_2") = PathtoFile
: rstLog.Fields("File_2") = FileName
: rstLog.Fields("Path_3") = PathtoFile
: rstLog.Fields("File_3") = FileName
:
: rstLog.Update
: ~~~~~~~~~~
:
:
: This Updating statement is inside of a Do while....Loop statement which
: looks like this:
: ~~~~~~~~~
:
: lngCurrentBegin = instr(1,strDataWhole,strBoundry)
: lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
:
: countloop = 0
:
: Do While lngCurrentEnd > 0
:
: ......... among some other code here is also the Updating code
: above .......
:
: lngCurrentBegin = lngCurrentEnd
: lngCurrentEnd = instr(lngCurrentBegin + 9 ,strDataWhole,strBoundry) - 1
:
: 'Prevents infinate loop.
: countloop = countloop + 1
: if countloop = 100 Then
: Response.Write "looping 100 times.Terminating script !"
:
: if rstLog.State then rstLog.close
:
: Response.End
: End if
:
: loop
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #3 by "Mircea Goia" <mircea@c...> on Mon, 29 Jul 2002 10:52:18
|
|
Here's my whole code:
~~~~~~~~~~~~~
Server.ScriptTimeout=300
ForWriting = 2
adLongVarChar = 201
lngNumberUploaded = 0
id_company=request("id_company")
'Create a database connection
'set conn_pop = server.createobject("adodb.connection")
Set rstLog = server.createobject("adodb.recordset")
'on error resume next
rstLog.ActiveConnection ="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\inetpub\wwwroot\jiuvalley\data1\elisting.mdb;"
'Create a recordset
rstLog.Source = "Select * from firme"
rstLog.CursorType = 0
rstLog.CursorLocation = 2
rstLog.LockType = 3
rstLog.Open
rstLog_numRows = 0
'Open recordset
'rstLog.Open "Select * from popup", conn_pop, 3, 3, 1
'Get binary data from form
noBytes = Request.TotalBytes
binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
Set RST = CreateObject("ADODB.Recordset")
LenBinary = LenB(binData)
if LenBinary > 0 Then
RST.Fields.Append "myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("myBinary")
End if
'get the boundry indicator
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8
strBoundry = "--" & right(strBoundry,len(strBoundry)-
lngBoundryPos)
SavePath = Server.MapPath("../../../data1/elisting/")
text_firma=ParseForm("TArea").item(0)
if text_firma="" or isnull(text_firma) then
response.write "<font face=arial,helvetica size=2
color=#ff0000><b>Eroare !</b><br><br> Ati uitat sa completati textul
pentru pop-up !<br><br><a href=javascript:history.go(-1)>Inapoi</a></font>"
response.end
end if
'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
countloop = 0
Do While lngCurrentEnd > 0
'Get the data between current boundry
'and remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, (lngCurrentEnd -
lngCurrentBegin) + 1)
'Get the full path of the current file.
lngBeginFileName = instr(1,strdata,"filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34))
'Make sure they selected at least one
'file.
if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then
Response.Write "<font face=arial,helvetica size=2
color=#ff0000><b>Eroare !</b><br><br> Trebuie sa alegeti macar o imagine
pentru aceasta firma !<br><br><a href=javascript:history.go(-1)
>Inapoi</a></font>"
Response.End
End if
'There could be one or more empty file b
'
'
' oxes.
if lngBeginFileName <> lngEndFileName and lngBeginFileName - 10 <>
0 Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName -
lngBeginFileName)
'Loose the path information and keep
'just the file name.
tmpLng = instr(1,strFilename,"\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"\")
Loop
FileName = right(strFilename,len(strFileName) - PrevPos)
'Get the begining position of the file
'data sent.
'if the file type is registered with the browser then there will be a
Content-Type
lngCT = instr(1,strData,"Content-Type:")
if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr
(10)) + 4
Else
lngBeginPos = lngEndFileName
End if
'Get the ending position of the file
'data sent.
lngEndPos = len(strData)
'Calculate the file size.
lngDataLenth = (lngEndPos - lngBeginPos) -1
'Get the file data
strFileData = mid(strData,lngBeginPos,lngDataLenth)
'Create the file.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(SavePath & "\" & FileName,
ForWriting, True)
f.Write strFileData
Set f = nothing
Set fso = nothing
PathtoFile="../../data1/elisting/"& FileName
'''''''' writing Upload Information to the database '''''''''''''
rstLog.Fields("Path_1") = PathtoFile
rstLog.Fields("File_1") = FileName
rstLog.Fields("Path_2") = PathtoFile
rstLog.Fields("File_2") = FileName
rstLog.Fields("Path_3") = PathtoFile
rstLog.Fields("File_3") = FileName
rstLog.Fields("text_firma") = text_firma
rstLog.Update
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
if lngNumberUploaded = 0 Then
Response.Write "<html><head><title>Succes !
</title></head><body><STRONG>Pop-up-ul a fost construit !</STRONG><BR><BR>"
End if
Response.Write SavePath & "\" & FileName & "<BR>"
lngNumberUploaded = lngNumberUploaded + 1
End if
'Get then next boundry postitions if
'any.
lngCurrentBegin = lngCurrentEnd
lngCurrentEnd = instr(lngCurrentBegin +
9 ,strDataWhole,strBoundry) - 1
'Prevents infinate loop.
countloop = countloop + 1
if countloop = 100 Then
Response.Write "S-a incercat de 100 de ori.
Executia scriptului s-a oprit !"
'Close the Log
if rstLog.State then rstLog.close
'if conn.State then conn.Close
Response.End
End if
loop
'Close the Log
if rstLog.State then rstLog.close
'if conn.State then conn.Close
Response.Write "<br><br><b>" & lngNumberUploaded & "</b>
imagini au fost incarcate pe server."
Response.Write "<BR><BR><a
href='saveany.asp'>Inapoi</a><br><br><a href='JavaScript:onClick=
window.close()'>Inchide fereastra</a></body></html>"
~~~~~~~~~
Thank you,
Mircea
> Where is the code where you put the values into the recordset?
Are you calling .AddNew within each loop?
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Mircea Goia" <mircea@c...>
Subject: [access_asp] A database updating question...(using Rs.Update)
: Hi,
:
: I have a table (in Access 2000) which (among others) has these columns:
: Path_1, File_1, Path_2, File_2 ,Path_3, File_3.
:
: And I have a script which uploads three files to the disk.
: After uploading the files to the disk I want to write in the database the
: path to every file and every file name.
:
: I want that in the field "Path_1" to have the path to the file number 1
: and in the field "File_1" to have the name of the file number 1.
: And so on...
:
: I use Rs.Update method:
: ~~~~~~~
: rstLog.Fields("Path_1") = PathtoFile
: rstLog.Fields("File_1") = FileName
: rstLog.Fields("Path_2") = PathtoFile
: rstLog.Fields("File_2") = FileName
: rstLog.Fields("Path_3") = PathtoFile
: rstLog.Fields("File_3") = FileName
:
: rstLog.Update
: ~~~~~~~~~~
:
:
: This Updating statement is inside of a Do while....Loop statement which
: looks like this:
: ~~~~~~~~~
:
: lngCurrentBegin = instr(1,strDataWhole,strBoundry)
: lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
:
: countloop = 0
:
: Do While lngCurrentEnd > 0
:
: ......... among some other code here is also the Updating code
: above .......
:
: lngCurrentBegin = lngCurrentEnd
: lngCurrentEnd = instr(lngCurrentBegin + 9 ,strDataWhole,strBoundry) - 1
:
: 'Prevents infinate loop.
: countloop = countloop + 1
: if countloop = 100 Then
: Response.Write "looping 100 times.Terminating script !"
:
: if rstLog.State then rstLog.close
:
: Response.End
: End if
:
: loop
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Message #4 by "Ken Schaefer" <ken@a...> on Tue, 30 Jul 2002 12:26:39 +1000
|
|
Hi,
You are using the same variable three times when populating the fields in
the database (explained offlist)
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Mircea Goia" <mircea@c...>
Subject: [access_asp] Re: A database updating question...(using Rs.Update)
: Here's my whole code:
: ~~~~~~~~~~~~~
: Server.ScriptTimeout=300
: ForWriting = 2
: adLongVarChar = 201
: lngNumberUploaded = 0
: id_company=request("id_company")
:
: 'Create a database connection
: 'set conn_pop = server.createobject("adodb.connection")
:
: Set rstLog = server.createobject("adodb.recordset")
:
: 'on error resume next
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
 |