Link to home
Start Free TrialLog in
Avatar of phillystyle123
phillystyle123Flag for United States of America

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.ContentID - here's my code:

<%
      Set Upload = Server.CreateObject("Persits.Upload")

      ' Capture files
      Upload.Save "E:\inetpub\wwwroot\smbb\newsite\news\pdfs\"

      ' Obtain file object
      Set File = Upload.Files("THEFILE")

      For Each File in Upload.Files

            datapath="E:\inetpub\wwwroot\smbb\smbb.mdb"
            strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & datapath
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open strConn  
            







 

      
            set rs = Server.CreateObject("ADODB.RecordSet")
      
Dim rsContentID__MMColParam
rsContentID__MMColParam = "ContentID"
rsContentID.Source = "SELECT * FROM Content WHERE ContentID = " + Replace(rsContentID__MMColParam, "'", "''") + "" 
            
            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!
Avatar of alorentz
alorentz
Flag of United States of America image

@ different recordset names...


Change to :

rs.Source = "SELECT * FROM Content WHERE ContentID = " + Replace(rsContentID__MMColParam, "'", "''") + "" 
And, as always,...stop using Dreamweaver.  It's the DEVIL!
ASKER CERTIFIED SOLUTION
Avatar of alorentz
alorentz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of phillystyle123

ASKER

thanks alorentz! code worked perfectly
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!
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.
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