Attaching Files to a VB6 form to send to database

I am at my next learning challenge.  I want to be able to attach a Microsoft Excel, Word or picture file and send it to an sql database using Visual Basic 6 as I have a program that is written in that language.  Are there any good code examples that I can start out with?  What components or references do I need to load?   What controls do I use?

Thanks for help in this regards to get me started.  Of course I will have follow up questions to this one I started.
al4629740Asked:
Who is Participating?
 
Claire StrebSoftware GuruCommented:
In line 18/19, how do I locate the file?  It depends on your situation.  You can have the user browse using the FileDialog, for example (https://msdn.microsoft.com/en-us/library/aa716248(v=vs.60).aspx).

Would I put the path to the file?  (ie c:/users/desktop/tempfile) Yes, but it is common practice to use backslashes (\) instead of slashes (/) for VB6 and Windows (c:\users\userName\desktop\tempfile).

Also, on line 37, what type of file am I writing to?  The example is for an image, what you call a picture file.  

I advise you to read some good VB6 books, such as "Visual Basic 6 Client/Server Programming Gold Book".
0
 
Claire StrebSoftware GuruCommented:
Here is an example for making a file into a stream to store in SQL Server:  http://www.devx.com/tips/Tip/14246
That being said, many people store their files in a folder and just store the full path to it in the database.
It depends what you want.

Hope this helped you,
Claire
1
 
al4629740Author Commented:
My program sends data over the Internet to the database.  So I’m not sure which method will work better because the file has to be transferred over the Internet anyways.
0
 
al4629740Author Commented:
So here is the code from that link you sent below.  In line 18/19, how do I locate the file?  Would I put the path to the file?  (ie c:/users/desktop/tempfile)  Also, on line 37, what type of file am I writing to?  Word doc?

dim rst as new adodb.recordset
dim adoConn as new adodb.Connection
You also have to open the connection with the database.
 'Open recordset....
rst.Open "Select * from <TABLE> 
where <CONDITION>", adoConn, adOpenKeyset,
adLockOptimistic


'THIS FUNCTION SAVES AN IMAGE 
INTO AN IMAGE DATATYPE FIELD
Private Function SaveImage()
  Dim mStream As New ADODB.Stream

  With mStream
    .Type = adTypeBinary
    .Open
    .LoadFromFile "<IMAGE FILE 
NAME>"
    rst("<IMAGE FIELD NAME>"). 
Value = .Read
    rst.Update
  End With
  Set mStream = Nothing
End Function

'THIS FUNCTION LOAD IMAGE FROM 
IMAGE DATATYPE FIELD AND SAVE IT INTO A
FILE.....
Private Function LoadImage()
  Dim mStream As New ADODB.Stream

  With mStream
    .Type = adTypeBinary
    .Open
    .Write rst("<IMAGE FIELD NAME>")
    .SaveToFile "<DESTINATION FILE 
NAME>", adSaveCreateOverWrite
  End With

  Set mStream = Nothing

End Function

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.