Original address: http://dotnet.aspx.cc/ShowDetail.aspx? J9UBRVER-L3VB-49M3-GOU1-Z6C2PVR6FZ3K
I took out the key parts and made relevant modifications:
Picturebox1 is a picturebox control.
Name is varchar (50) type image is image type
Private Sub insertimage () Sub Insertimage () ' Insert images into the database
Dim Mystream As New Filestream ( " C: inetpubwwwrootwin2000.gif " , Filemode. Open, fileaccess. Read)
Dim Buffer (mystream. length) As Byte
Mystream. Read (buffer, 0 , Mystream. length)
Mystream. Close ()
Dim Sqlconnectionstring As String = " Persist Security info = false; Data Source =.; initial catalog = AA; user id = sa; Password ="
Dim Myconnection As New Sqlconnection (sqlconnectionstring)
Dim Mycommand As New Sqlcommand ( " Insert into Photos ([name], [Photo]) values (@ name, @ image) " , Myconnection)
Mycommand. Parameters. Add ( " @ Name " , " Test " )
Mycommand. Parameters. Add ( " @ Image " , Buffer)
Myconnection. open ()
Mycommand. executenonquery ()
Myconnection. Close ()
End sub
Private Sub showimage () Sub Showimage () ' Retrieve images from the database
Dim Sqlconnectionstring As String = " Persist Security info = false; Data Source =.; initial catalog = AA; user id = sa; Password ="
Dim Myconnection As New Sqlconnection (sqlconnectionstring)
Myconnection. open ()
Dim Mycommand As New Sqlclient. sqlcommand ( " Select photo from photos where [name] = 'test' " , Myconnection)
Dim Buffer () As Byte = Mycommand. executescalar ()
If ( Not Buffer Is Nothing ) Andalso (Buffer. Length > 0 ) Then
Dim Stream As New Memorystream (buffer, 0 , Buffer. length, True )
Picturebox1.image = New Bitmap (Stream)
Stream. Close ()
End If
Myconnection. Close ()
End sub