Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > ADO and Data source controls (picturebox)


Reply
 
Thread Tools Display Modes
  #1  
Old 07-08-2004, 09:59 AM
kesho kesho is offline
Regular
 
Join Date: Jul 2003
Posts: 79
Default ADO and Data source controls (picturebox)


I am having problems working out how to bind a picturebox to a ADO recorset to save and load pictures to a database.

I have tried the following:

Code:
Option Explicit
    Dim cnnCurtID As ADODB.Connection
    Dim rstID As New ADODB.Recordset
    
Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub cmdLoad_Click()
    If Not IsNumeric(Text1) Then Exit Sub
    If rstID.State = adStateOpen Then rstID.Close
    rstID.Open "SELECT * FROM ID WHERE MemberNo = " & txtMemNo & " ;", cnnCurtID, adOpenStatic, adLockOptimistic
    If Not rstID.EOF Then
      Set Signature.DataSource = rstID
      Signature.DataField = "Signature"
    End If
End Sub

Private Sub cmdSave_Click()
    If Not IsNumeric(txtMemNo) Then Exit Sub
    If rstID.EOF = True Then
        rstID.AddNew
    End If
    rstID!MemberNo = CLng(txtMemNo)
    rstID.Update
End Sub

Private Sub cmdSignature_Click()
    If BrowseToFile(CD, "Signature.bmp", "Bitmap files (*.bmp)|*.bmp|JPeg files (*.jpg)|*.jpg", "Open Signature file", , App.Path) = False Then
        MsgBox "Signature import cancelled", vbInformation + vbOKOnly, "Error"
        Exit Sub
    End If
    Signature.Picture = LoadPicture(CD.FileName)
    cmdSave.Enabled = True
End Sub

Private Sub Form_Load()
    Set cnnCurtID = New ADODB.Connection
    cnnCurtID.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\CurtID.mdb;Persist Security Info=False"
    cnnCurtID.Open
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If cnnCurtID.State = adStateOpen Then cnnCurtID.Close
    If rstID.State = adStateOpen Then rstID.Close
    Set cnnCurtID = Nothing
    Set rstID = Nothing
End Sub

Private Sub txtMemNo_Change()
    txtMemNo.SelStart = 0
    txtMemNo.SelLength = Len(txtMemNo)
    If Not IsNumeric(txtMemNo) Then Exit Sub
    If rstID.State = adStateOpen Then rstID.Close
    rstID.Open "SELECT * FROM ID WHERE MemberNo = " & txtMemNo & " ;", cnnCurtID, adOpenStatic, adLockOptimistic
    If Not rstID.EOF Then
        lblEOF.Visible = False
        Set Signature.DataSource = rstID
        Signature.DataField = "Signature"
    Else
        lblEOF.Visible = True
    End If
End Sub

Private Sub txtMemNo_GotFocus()
    txtMemNo.SelStart = 0
    txtMemNo.SelLength = Len(txtMemNo)
End Sub
Which works in a similar way to how I used to do it with a DataControl. However this does not seem to work in this case.

Any suggestions would be appreciated, as I am sure that I am just missing soneting simple.
Reply With Quote
  #2  
Old 07-08-2004, 10:40 AM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

If you are looking to load images into an Access database and retrieve them, I suggest reviewing this tutorial..it shows you a great method of doing this.

http://www.xtremevbtalk.com/showthread.php?t=11080

I would also suggest only storing the name and path of the image in the database. Storing images will cause the database to grow to a huge size, which will cause many different problems and could lead to corruption.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 07-08-2004, 12:10 PM
kesho kesho is offline
Regular
 
Join Date: Jul 2003
Posts: 79
Default

I have used that method for another part of the program where I have had the option, but I have been told I have to use a database and store the objects as an OLE object as we did using the datacontrol. There will also be OLE bitmaps stored in the database that we will have to be able to restore. So unfortunately I don't think I will be able to use this method.

Is there any way to save and restore pictures using ADO and DataSources?
Reply With Quote
  #4  
Old 07-08-2004, 12:18 PM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

First off I wouldn't use any ADODC or data controls for this. Use ADO connection and recordset objects. And, what within that tutorial example can't you use?

This is using ADO to connect to an Access database and retrieve an image. It also show you how to add a new image.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #5  
Old 07-08-2004, 01:04 PM
kesho kesho is offline
Regular
 
Join Date: Jul 2003
Posts: 79
Default

Maby i am wrong. I just thought that this metod wouldn't work when trying to load images stored using another method (i.e. DataControls with bound datafields). I will try it that way then, esspecialy as I have the coding for it.

Thanks for the reply.

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->