Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing Word Documents/Images in SQL Server database through VB

Status
Not open for further replies.

isha

MIS
Mar 7, 2002
216
IN
I have developed a package using VB and SQL server 7.0 database for maintaing records of Questions and Answers.
When we use the package some MS Word Files containing the answer text are added and saved in a separate folder through VB and the Question_no data is stored in a database table. I want to have an arrangement so that the Word document containing the text of answer is also stored in the database table. How can I do it through VB. Can a SQL table store a Word Document in its columns. Anyone who can help me is most welcome.
 
Use an Image data type and populate it using the TextStream object (MicroSoft Scripting RunTime). You need to store the word document in C:\Temp (or somewhere similar) temporarily and then read it as a text stream. Recover it by the reverse process.

I have used this for document templates and it works well. Key bits of the writing and reading code follow :

Set strDataStream = New ADODB.Stream
With strDataStream
.Type = adTypeBinary
.Open
.LoadFromFile cDocumentName
End With

With rsRecordSet

.AddNew
cDocumentContent = strDataStream.Read
.Fields("Doc").AppendChunk cDocumentContent
strDataStream.Close

End With

......................................................

Set l_strDataStream = New ADODB.Stream
With strDataStream
.Type = adTypeBinary
.Open
.Write rsTemp.Fields("Doc").Value
cDocumentName = CreateTemporaryFile("xxx")
.SaveToFile cDocumentName, adSaveCreateOverWrite
.Close
End With
Set strDataStream = Nothing

objWord.Documents.Open FileName:=cDocumentName,
ReadOnly:=False

 
StewartJ
Today I tried the method suggested by you. But it gave the error as 'user defined type not defined' on the first line-
Set strDataStream = New ADODB.Stream
Please suggest.
 
Did you set a reference to MicroSoft Scripting RunTime in Project|References ?
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
johnwm

Yes, i have set reference to MicroSoft Scripting RunTime in Project References.
Please help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top