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 IamaSherpa 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 in a database table 1

Status
Not open for further replies.

hpsingh

Programmer
Feb 27, 2002
13
IN
I am developing a package in which some MS Word documents are added at runtime. I do not want to store these documents only in a folder but I also want to store the Word Document in a SQL Server 7.0 database table column. I don't know the procedure/coding for doing this. Anyone who can help me, is most welcome.
 
Use a data stream object and store it in a binary/image field. You can read it back with something like this :

Set dsDataStream = New ADODB.Stream
With dsDataStream
.Type = adTypeBinary
.Open
.Write l_rsTemp.Fields("DocumentContent").Value
.SaveToFile strDocumentName, adSaveCreateOverWrite
.Close
End With
Set dsDataStream = Nothing
objWordApplication.Documents.Open FileName:=strDocumentName
 
Dear StewartJ
Very much thanks for the hint. I have not yet tried it.
I am new to VB programming.You have send me the code for opening/reading the data field but I do not know how to save the word document with the help of data stream object. I will be very thankfull if you can throw some light on it in details and with code. Thanks.
 
You need to have MicroSoft Scripting Runtime in your project references.

Set dsDataStream = New ADODB.Stream
With dsDataStream
.Type = adTypeBinary
.Open
.LoadFromFile strDocumentName
End With

' Insert details of the new version into a recordset
' Assume that it has an image field named Document
With rsDocumentRecord
.AddNew
strDocumentContent = dsDataStream.Read
.Fields("Document").AppendChunk strDocumentContent
dsDataStream.Close
End With

Set dsDataStream = Nothing

You can split the document into chunks of, say 4k, if you are concerned about memory usage but I have used the above as is on a 10Mb document without any problems.

Incidentally, I have not succeeded in passing the document content as a parameter to SQL Server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top