phillystyle123
asked on
UPDATE EXISTING RECORD IN MS ACESS USING ASPUPLOAD
I'm using ASPUpload to upload a file and add the filename to the db. i need to do this while UPDATING existing ms access db records. I've taken this code into the stratusphere somehow and I'm not sure where I'm going wrong. The form variable I'm tryiing to pass is ContentID. Basically I'm looking for this:
add filename to db record where ContentID=FormParam.Conten tID - here's my code:
<%
Set Upload = Server.CreateObject("Persi ts.Upload" )
' Capture files
Upload.Save "E:\inetpub\wwwroot\smbb\n ewsite\new s\pdfs\"
' Obtain file object
Set File = Upload.Files("THEFILE")
For Each File in Upload.Files
datapath="E:\inetpub\wwwro ot\smbb\sm bb.mdb"
strConn="Provider=Microsof t.Jet.OLED B.4.0;Data Source=" & datapath
Set objConn = Server.CreateObject("ADODB .Connectio n")
objConn.Open strConn
set rs = Server.CreateObject("ADODB .RecordSet ")
Dim rsContentID__MMColParam
rsContentID__MMColParam = "ContentID"
rsContentID.Source = "SELECT * FROM Content WHERE ContentID = " + Replace(rsContentID__MMCol Param, "'", "''") + ""
rs.Open "Content",objConn,1,2
if len(EditRecordFlag) = 0 then
rs.AddNew
end if
rs("filename") = File.ExtractFileName
rs.Update
rs.Close
set rs = nothing
objConn.Close
set objConn = nothing
Response.Write "Your PDF has been successfully uploadedd. <a href='index.asp'>Click here</a> to return to the admin."
Next
%>
thanks!
add filename to db record where ContentID=FormParam.Conten
<%
Set Upload = Server.CreateObject("Persi
' Capture files
Upload.Save "E:\inetpub\wwwroot\smbb\n
' Obtain file object
Set File = Upload.Files("THEFILE")
For Each File in Upload.Files
datapath="E:\inetpub\wwwro
strConn="Provider=Microsof
Set objConn = Server.CreateObject("ADODB
objConn.Open strConn
set rs = Server.CreateObject("ADODB
Dim rsContentID__MMColParam
rsContentID__MMColParam = "ContentID"
rsContentID.Source = "SELECT * FROM Content WHERE ContentID = " + Replace(rsContentID__MMCol
rs.Open "Content",objConn,1,2
if len(EditRecordFlag) = 0 then
rs.AddNew
end if
rs("filename") = File.ExtractFileName
rs.Update
rs.Close
set rs = nothing
objConn.Close
set objConn = nothing
Response.Write "Your PDF has been successfully uploadedd. <a href='index.asp'>Click here</a> to return to the admin."
Next
%>
thanks!
And, as always,...stop using Dreamweaver. It's the DEVIL!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
But, the whole logic of the ocde is wrong too...all it will do is overwrite the previous file if the user uplaod more than one. If they only upload one, then it's fine. More than one, will just overwrite each time.
ASKER
thanks alorentz! code worked perfectly
ASKER
i'm just uploading the one file - so i think it should work fine
Ladies and gentlemen...we have a first! I have actually, successfully, provided a Dreamweaver answer.
Not sure whether to pat myself on the back, or jump off a bridge...(I'm sure many here would say jump).
Good luck!
Not sure whether to pat myself on the back, or jump off a bridge...(I'm sure many here would say jump).
Good luck!
ASKER
well, it's not all dw - some was actual honest code - ;-)
True...probably why I could support it <grin>...keep moving away from DW code.
ASKER
hey alorentz - i just posted another ? related to this one - basically, i'm not able to update existing records with this code - check it out if you get a sec:
https://www.experts-exchange.com/questions/21919484/ASPUpload-updating-existing-record-using-form-param-PT-II.html
and thanks again for the help
https://www.experts-exchange.com/questions/21919484/ASPUpload-updating-existing-record-using-form-param-PT-II.html
and thanks again for the help
Change to :
rs.Source = "SELECT * FROM Content WHERE ContentID = " + Replace(rsContentID__MMCol