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. General Programming
  3. C#
  4. inserting images into access database

inserting images into access database

Scheduled Pinned Locked Moved C#
tutorialdatabase
6 Posts 5 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.
  • S Offline
    S Offline
    Steve1_rm
    wrote on last edited by
    #1

    Hello I am creating a database which will be used to display information and pictures for houses. I have done everything but be able to insert the pictures and retrieve them from the database. This is the code l am using to make the connection with the database //Example Connection m_cnADONetConnection.ConnectionString = @"Provider=Microsoft.jet.OLEDB.4.0;data source=C:\Houses"; m_daDataAdapter = new OleDbDataAdapter("Select * From Houses",m_cnADONetConnection); OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daAdapter); m_daDataAdapeter.Fill(m_dtContacts); //This is what i am using to retrieve from the database, not sure how to do this for a image control. txtHouseID.text = Rows[rowPosition]["HouseID"].ToString(); To select the picture l want to add to the database, l am using a open dialog box, which works, but l can't add it to the database. Many thanks in advance Steve

    H B M 3 Replies Last reply
    0
    • S Steve1_rm

      Hello I am creating a database which will be used to display information and pictures for houses. I have done everything but be able to insert the pictures and retrieve them from the database. This is the code l am using to make the connection with the database //Example Connection m_cnADONetConnection.ConnectionString = @"Provider=Microsoft.jet.OLEDB.4.0;data source=C:\Houses"; m_daDataAdapter = new OleDbDataAdapter("Select * From Houses",m_cnADONetConnection); OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daAdapter); m_daDataAdapeter.Fill(m_dtContacts); //This is what i am using to retrieve from the database, not sure how to do this for a image control. txtHouseID.text = Rows[rowPosition]["HouseID"].ToString(); To select the picture l want to add to the database, l am using a open dialog box, which works, but l can't add it to the database. Many thanks in advance Steve

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      First, learn to use OleDbParameter. This will greatly aide in your problems. Second, set the column in which you want to store the image to an OLEObject. Then, you need to be able to read the image from a Stream as a byte[] array and assign it:

      OleDbCommand cmd = conn.CreateCommand();
      cmd.CommandText = "INSERT INTO SomeTable (Name, Image) " +
      "VALUES (@Name, @Image)";
      cmd.Parameters.Add("@Name", OleDbType.VarWChar, 40).Value = "ImageName";
      cmd.Parameters.Add("@Image", OleDbType.Binary).Value = image;
      cmd.ExecuteNonQuery();

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      A 1 Reply Last reply
      0
      • H Heath Stewart

        First, learn to use OleDbParameter. This will greatly aide in your problems. Second, set the column in which you want to store the image to an OLEObject. Then, you need to be able to read the image from a Stream as a byte[] array and assign it:

        OleDbCommand cmd = conn.CreateCommand();
        cmd.CommandText = "INSERT INTO SomeTable (Name, Image) " +
        "VALUES (@Name, @Image)";
        cmd.Parameters.Add("@Name", OleDbType.VarWChar, 40).Value = "ImageName";
        cmd.Parameters.Add("@Image", OleDbType.Binary).Value = image;
        cmd.ExecuteNonQuery();

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Thanks for your help I was starting to read up on the stream. Could you give me a example how to read the image from a stream as a byte data. I am interested in using the parameters more, as it seems to be very useful. Is there any good tutorial on them. Many thanks in advance Steve

        H 1 Reply Last reply
        0
        • A Anonymous

          Thanks for your help I was starting to read up on the stream. Could you give me a example how to read the image from a stream as a byte data. I am interested in using the parameters more, as it seems to be very useful. Is there any good tutorial on them. Many thanks in advance Steve

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          There's the .NET Framework SDK documentation - just type OleDbParameter in the index. There's probably tutorials on this site and around the 'net, but they're not hard to use and the documentation offers plenty of information and examples.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          1 Reply Last reply
          0
          • S Steve1_rm

            Hello I am creating a database which will be used to display information and pictures for houses. I have done everything but be able to insert the pictures and retrieve them from the database. This is the code l am using to make the connection with the database //Example Connection m_cnADONetConnection.ConnectionString = @"Provider=Microsoft.jet.OLEDB.4.0;data source=C:\Houses"; m_daDataAdapter = new OleDbDataAdapter("Select * From Houses",m_cnADONetConnection); OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daAdapter); m_daDataAdapeter.Fill(m_dtContacts); //This is what i am using to retrieve from the database, not sure how to do this for a image control. txtHouseID.text = Rows[rowPosition]["HouseID"].ToString(); To select the picture l want to add to the database, l am using a open dialog box, which works, but l can't add it to the database. Many thanks in advance Steve

            B Offline
            B Offline
            Bo Hunter
            wrote on last edited by
            #5

            The OLE DB .NET Provider does not support named parameters for passing parameters to a SQL Statement or a stored procedure called by an OleDbCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example: SELECT * FROM Customers WHERE CustomerID = ? As a result, the order in which OleDbParameter objects are added to the OleDbParameterCollection must directly correspond to the position of the question mark placeholder for the parameter. Thank You Bo Hunter

            1 Reply Last reply
            0
            • S Steve1_rm

              Hello I am creating a database which will be used to display information and pictures for houses. I have done everything but be able to insert the pictures and retrieve them from the database. This is the code l am using to make the connection with the database //Example Connection m_cnADONetConnection.ConnectionString = @"Provider=Microsoft.jet.OLEDB.4.0;data source=C:\Houses"; m_daDataAdapter = new OleDbDataAdapter("Select * From Houses",m_cnADONetConnection); OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daAdapter); m_daDataAdapeter.Fill(m_dtContacts); //This is what i am using to retrieve from the database, not sure how to do this for a image control. txtHouseID.text = Rows[rowPosition]["HouseID"].ToString(); To select the picture l want to add to the database, l am using a open dialog box, which works, but l can't add it to the database. Many thanks in advance Steve

              M Offline
              M Offline
              Mazdak
              wrote on last edited by
              #6

              http://www.codeproject.com/cs/database/albumviewer.asp[^] Mazy No sig. available now.

              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