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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.