How to Upload Images to a Access Database from an asp page

Discussion in 'C#' started by bloggerpro, Aug 17, 2007.

  1. #1
    can someone help me out with the script.....
     
    bloggerpro, Aug 17, 2007 IP
  2. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #2
    Hello,

    Hope this code might be useful to you.

    Dim myupload
    'declare variables..
    intCount=0

    ' Create Upload Component
    Set myupload = Server.CreateObject("aspSmartUpload.SmartUpload")
    myupload.Upload

    'Create Connection
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Server.MapPath("data.mdb")

    Set Rs = Server.CreateObject("ADODB.recordset")
    Rs.Open "SELECT user_id,user_name,user_photo FROM users", Conn,3,3

    'Select each file
    For each file In myupload.Files
    If not file.IsMissing Then 'Check for missing file
    'Add the current file in database
    Rs.AddNew
    file.FileToField Rs.Fields("user_photo")
    Rs("user_name") = myupload.Form("USERNAME")
    Rs.Update
    intCount = intCount + 1
    End If
    Next
    Response.Write(intCount & " file(s) uploaded.")
    'Destroy the objects...

    Thanks

    Mayur Gondaliya
     
    MayurGondaliya, Aug 18, 2007 IP