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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. insert image to Sql Data base

insert image to Sql Data base

Scheduled Pinned Locked Moved C#
databasehelp
4 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.
  • V Offline
    V Offline
    v_sadeghpour
    wrote on last edited by
    #1

    hello i would like insert a image in sql Data base with oledb Connection. please help me.:doh: vahid

    J B 2 Replies Last reply
    0
    • V v_sadeghpour

      hello i would like insert a image in sql Data base with oledb Connection. please help me.:doh: vahid

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      A simple Google search returned these results[^].

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Goof around music jam with my brothers (with video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      1 Reply Last reply
      0
      • V v_sadeghpour

        hello i would like insert a image in sql Data base with oledb Connection. please help me.:doh: vahid

        B Offline
        B Offline
        Billah
        wrote on last edited by
        #3

        i think following code will help u: 1st Step: Take pic. box 2nd Step: Take a Button and Text box to take the image, which u want to save into Database

        buff = new byte [ f.Length ] ; f.Read ( buff, 0, ( int ) f.Length ) ; MemoryStream ms= new MemoryStream(buff,0,buff.Length); Image i = Image.FromStream ( ms ) ; img.Image = i ; f.Close(); } catch(Exception ee) { MessageBox.Show("An error has occured.\n" + ee.Message); } } }
        3rd Step: Create table where take one field which will image type CREATE TABLE [dbo].[tableName] ([img_name] [image] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO
        buff = new byte [ st.Length ] ; st.Read ( buff, 0, ( int ) st.Length ) ; try { using(SqlConnection conn = new SqlConnection()) { conn.ConnectionString = dbcon; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "insert into tableName(imageName) values(@pict)"; cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@pict",buff); cmd.ExecuteNonQuery(); } } catch(SqlException sqle) { Console.WriteLine(sqle.Message); } st.Close(); } private void linklblShowPicture_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { try { using(SqlConnection conn = new SqlConnection()) { conn.ConnectionString = dbcon; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "select imageName from tableName where .... "; \\here u can use track id in datatabel to select, update or delete image cmd.Connection = conn; cmd.CommandType = CommandType.Text; SqlDataReader r = cmd.ExecuteReader(); if(r.R

        V 1 Reply Last reply
        0
        • B Billah

          i think following code will help u: 1st Step: Take pic. box 2nd Step: Take a Button and Text box to take the image, which u want to save into Database

          buff = new byte [ f.Length ] ; f.Read ( buff, 0, ( int ) f.Length ) ; MemoryStream ms= new MemoryStream(buff,0,buff.Length); Image i = Image.FromStream ( ms ) ; img.Image = i ; f.Close(); } catch(Exception ee) { MessageBox.Show("An error has occured.\n" + ee.Message); } } }
          3rd Step: Create table where take one field which will image type CREATE TABLE [dbo].[tableName] ([img_name] [image] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO
          buff = new byte [ st.Length ] ; st.Read ( buff, 0, ( int ) st.Length ) ; try { using(SqlConnection conn = new SqlConnection()) { conn.ConnectionString = dbcon; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "insert into tableName(imageName) values(@pict)"; cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@pict",buff); cmd.ExecuteNonQuery(); } } catch(SqlException sqle) { Console.WriteLine(sqle.Message); } st.Close(); } private void linklblShowPicture_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { try { using(SqlConnection conn = new SqlConnection()) { conn.ConnectionString = dbcon; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "select imageName from tableName where .... "; \\here u can use track id in datatabel to select, update or delete image cmd.Connection = conn; cmd.CommandType = CommandType.Text; SqlDataReader r = cmd.ExecuteReader(); if(r.R

          V Offline
          V Offline
          v_sadeghpour
          wrote on last edited by
          #4

          Thank you. vahid

          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