|
|
Title | Save and display images in a database using a PictureBox |
Keywords | database, image, picture, PictureBox |
Categories | Database, Graphics |
|
|
Use a bound PictureBox control to display the images. Use a Data control's Recordset object's AddNew and Update methods to create new records. When you are creating a new record, set the PictureBox's picture to the desired image. When you accept the changes, the image is stored in the database.
|
|
Private Sub Command1_Click()
Dim the_title As String
Dim the_isbn As String
Dim the_url As String
the_title = InputBox$("Title")
If Len(the_title) = 0 Then Exit Sub
the_url = InputBox$("URL")
If Len(the_url) = 0 Then Exit Sub
the_isbn = InputBox$("ISBN")
If Len(the_isbn) = 0 Then Exit Sub
dlgFile.Flags = _
cdlOFNExplorer Or _
cdlOFNFileMustExist Or _
cdlOFNHideReadOnly Or _
cdlOFNLongNames
dlgFile.DialogTitle = "Image File"
dlgFile.CancelError = True
On Error Resume Next
dlgFile.ShowOpen
If Err.Number = cdlCancel Then
Exit Sub
ElseIf Err.Number <> 0 Then
MsgBox "Error " & Err.Number & " selecting file." & _
vbCrLf & Err.Description
Exit Sub
End If
Data1.Recordset.AddNew
lblTitle.Caption = the_title
lblISBN.Caption = the_isbn
Data1.Recordset!URL = the_url
Picture1.Picture = LoadPicture(dlgFile.FileName)
Data1.Recordset.Update
Data1.Refresh
Data1.Recordset.FindFirst "URL = '" & the_url & "'"
End Sub
|
|
When you click on the label displaying the book's URL, the program uses the ShellExecute API function to display the URL in the system's default Web browser.
|
|
' Display the Web page.
Private Sub lblTitle_Click()
ShellExecute hwnd, "open", _
Data1.Recordset!URL, _
vbNullString, vbNullString, SW_SHOW
End Sub
|
|
This technique was adopted from my book "Advanced Visual Basic Techniques" (http://www.vb-helper.com/avbt.htm). I wrote that book in prehistoric times when VB4 ruled the Earth (1997), so it some of the programs need to be reworked to make them work in VB6, but it does describe some useful techniques.
|
|
|
|
|
|