vb.net access to the image in the database Montaque (original)
In the case of MS's own database Northwnd, one of the tables is categories, there are four four segments, one of which is the picture field of image type. First, we add a BMP image to the last line of pictures, It is then read out and displayed in the image control.
Add a SqlDataAdapter1, use the wizard to set the join database as the NORTHWND,SQL statement for SELECT [Category ID], [Category Name], Description, picture from Categories. Generate a DataSet for DataSet1. Then add two buttons to write the picture to the database and read the database, and an image control to display the picture.
Add the following code
Private Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill (DataSet11)
End Sub
' Read the picture from the database for temporary storage as monkey.bmp, and then load it into the image control.
Private Sub button2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Loadpicfromdb.click
Try
Dim 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 Try
End Sub
' Put the C:\6.bmp in the storage, you can change to your own picture.
Private Sub button3_click (ByVal sender as System.Object, 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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.