Vb.NET Insert Image File to Picturebox and store it to database.mdf

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)

Sorry for my bad English :) Thanks

Upvotes: 0

Views: 2895

Answers (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.

Upvotes: 1

Related Questions