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. how to insert image from picturebox to database

how to insert image from picturebox to database

Scheduled Pinned Locked Moved C#
databasehelpgraphicsregextutorial
4 Posts 4 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.
  • F Offline
    F Offline
    fofoth
    wrote on last edited by
    #1

    im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..

    N D G 3 Replies Last reply
    0
    • F fofoth

      im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..

      N Offline
      N Offline
      neyerMat
      wrote on last edited by
      #2

      you need to save the picture as bytes not as system.drawing.image object. the Dtabase don't know object there are just 0 and 1 ;-) But please don't ask me how to convert a image into a byte array...

      1 Reply Last reply
      0
      • F fofoth

        im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        as both errors indicate - the last parameter expects a byte array (byte[]) but your passing an Image object. Convert the image to a byte array first (maybe by saving to a memory stream? - google for best solution!) then pass that to the method instead.

        System.IO.MemoryStream memStream = new System.IO.MemoryStream();
        gambarPictureBox.Image.Save(memStream, gambarPictureBox.Image.RawFormat);
        byte[] imageBytes = memStream.ToArray();

        To load you'll have to do the reverse.

        Dave

        modified on Monday, June 2, 2008 6:37 AM

        1 Reply Last reply
        0
        • F fofoth

          im doing a project about RFID system registration.. database-ms access database name=registerDBDataSet table=ASAS column=GAMBAR in my form i have a gambarPictureBox,which retrieve the image from my pc(use browse button) from openFileDialog.. when run the program the image is open in the pictureBox and i want to save the image to database.. which way can i use? since many coding that i search from internet using sql command,is there any other way to retrieve image from picture box and insert it into database? the error happen when this code run: private void saveButton_Click(object sender, EventArgs e) { this.aSASTableAdapter.Insert(nameTextBox.Text, tptLhrTextBox.Text, trhLhrTextBox.Text, jantinaTextBox.Text, kaumTextBox.Text, agamaTextBox.Text, wargaTextBox.Text, statusTextBox.Text, ICTextBox.Text,gambarPictureBox.Image); this.aSASTableAdapter.Fill(this.registerDBDataSet.ASAS); } ---->Error 1:The best overloaded method match for 'Registration.registerDBDataSetTableAdapters.ASASTableAdapter.Insert(string, string, string, string, string, string, string, string, string, byte[])' has some invalid arguments ---->Error 2: Argument '10': cannot convert from 'System.Drawing.Image' to 'byte[]' C:\Documents and Settings\fathiah.FATHIA-582A635D\Desktop\Registration\registerForm.cs how to solve it.. please help me..

          G Offline
          G Offline
          Gareth H
          wrote on last edited by
          #4

          fofoth, This should help[^]

          Regards, Gareth. (FKA gareth111)

          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