Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to save image(.jpg) file in database

How to save image(.jpg) file in database

Scheduled Pinned Locked Moved ASP.NET
databasetutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MissionSuccess
    wrote on last edited by
    #1

    I have a .jpg file on my desktop. How to save it in the database. so that i can use it in my report. Thanks

    T N 2 Replies Last reply
    0
    • M MissionSuccess

      I have a .jpg file on my desktop. How to save it in the database. so that i can use it in my report. Thanks

      T Offline
      T Offline
      Tech_spidy
      wrote on last edited by
      #2

      you have to store the image in binary format. so that u can fetch from database

      Tech_spidy

      M 1 Reply Last reply
      0
      • T Tech_spidy

        you have to store the image in binary format. so that u can fetch from database

        Tech_spidy

        M Offline
        M Offline
        MissionSuccess
        wrote on last edited by
        #3

        ya i have little bit idea i want to take the image by using Html fileinputbox control and from the specified path,i want to retrieve only the filename(not path). and store that file(binary data) in one of my image field. can u give me some code for doing this...... my code is.................. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'Dim str As String = Me.File1.Value() 'If InStr(str, ".jp") > 0 Then ' 'File1.PostedFile.InputStream() 'Else ' Exit Sub 'End If Dim myStream As Stream myStream = File1.PostedFile.InputStream Dim ImgLength As Int64 = File1.PostedFile.ContentLength Dim ImgBinaryData(ImgLength) As Byte Dim n As Int64 = myStream.Read(ImgBinaryData, 0, ImgLength) saveimage(ImgBinaryData) End Sub Public Sub saveimage(ByVal mImageFileData As Byte()) Try Dim myTable As DataTable Dim myRow As DataRow conn = New SqlConnection(constr) conn.Open() cmd = New SqlCommand("spr_insertImage", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add(New SqlParameter("@ImageData", mImageFileData)) cmd.ExecuteNonQuery() conn.Close() Catch ex As Exception lblError.Text = ex.Message End Try End Sub but its not working...... any help

        1 Reply Last reply
        0
        • M MissionSuccess

          I have a .jpg file on my desktop. How to save it in the database. so that i can use it in my report. Thanks

          N Offline
          N Offline
          Neeraj Arora
          wrote on last edited by
          #4

          Have you used the image datatype in database?

          M 1 Reply Last reply
          0
          • N Neeraj Arora

            Have you used the image datatype in database?

            M Offline
            M Offline
            MissionSuccess
            wrote on last edited by
            #5

            ya i have used image datatype.... but after inserting i m getting in the database...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups