0

I have a table which have image data type in one of the colomn , I try this code,

first, is this a right code to insert one row of the table?

Me.DatasiswaTableAdapter.Insert(NISTextBox.Text, NamaTextBox.Text, KelasTextBox.Text, JurusanTextBox.Text, Jenis_KelaminComboBox.Text, Tanggal_LahirDateTimePicker.ToString, AlamatRichTextBox.Text, FotoPictureBox.Image)
  • if yes then I need to know why the image type is change to byte? and how to insert the image from picturebox if the format of the code is a byte?

  • then if no please let me know the right code

Sorry for my bad English :) Thanks

4
  • make use of "@" to insert row into database. Commented Oct 15, 2013 at 7:36
  • can you give me a sample with your own statement, so i can try it to my script Commented Oct 15, 2013 at 7:50
  • please show ur code ... Commented Oct 15, 2013 at 8:11
  • i got this, net-informations.com/vbprj/dataset/insert-image.htm can you tell me what is this mean? cmd.Parameters.AddWithValue("@id", id) Commented Oct 15, 2013 at 9:49

1 Answer 1

1

the net-informations link you posted should be very helpful if you study it.

it means a)the column you want to store the image to in SQL server must be defined as image. If you are using a different DB such as Access, depending on the version you might need to define it as Object or something similar. b) in the example, the image is converted to a stream (using image.save) then the stream to a byte array for storing in the DB.

you may want to store a bit more information about the image. getting it back to an image will just be the reverse (db -> byte array -> stream), but you are not going to know whether it was JPG, PNG, TIFF etc. If you think you will ever want to recreate it as a disk file in its original format, store the MIME type as well.

Sign up to request clarification or add additional context in comments.

1 Comment

wow,there are many things I don't know,perhaps I'll learn it from that link about converting image to byte by stream,.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.