Take the database Northwnd with MS as an example, some of which are categories, there are four four segments, one of which is an Image type Picture field. We first add a BMP picture to the last line of Picture, then read it Displayed in the image control.
Add a SqlDataAdapter1, set the join database with the wizard to NorthWnd, SQL statement for select [category ID], [category name], Description, Picture from categories. Generate a dataset to DataSet1. Then add two buttons to write a picture to the database. And reading the database, there is an image control to display a picture.
Add the following code
Private Sub Form1_Load (Byval e as system.EventArgs) Handles mybase.load sqldataadapter1.fill (DataSet11) End Sub
'Read the image from the database is temporarily stored as monkey.bmp, then load it into the image control. Private sub button2_click (Byval e as system.EventArgs) Handles LoadPicFromDb.Click try Data as Byte () = DataSet11.Tables (0) .ROWS (7) .Item (3) Dim MyFileStream as new system.io.filestream (Application.Startuppath & "/monkey.bmp", IO.FILEMODE.CREATE) MyFileStream.write (data, 0 , DATA.LENGTH) MyFileStream.close () PictureBox1.Image = New Bitmap (Application.startuppath & "/monkey.bmp") Catch End Sub
'Write the C: /6.BMP into the library, you can change to your own picture. Private sub button3_click (Byval E AS System.EventArgs) Handles InsertPictodb.Click Dim MyFileStream As New System.io .Filestream ("C: /6.BMP", IO.FILEMODE.Open) Dim Data () AS BYTE Redim Data (MyFileStream.length - 1) MyFileStream.Read (Data, 0, MyFileStream.length) MyFileStream.close () DataSet11.Tables (0) .ROWS (7) .Item (3) = data sqldataadapter1.Update (DataSet11.Getchanges ()) End Sub