Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Posts
    176

    Unanswered: storing a word file in DB

    How can i store a word file in my database table..

  2. #2
    Join Date
    Aug 2003
    Location
    Kingston, Ontario
    Posts
    106
    Using what? SQL SP or VB? With VB it's trivial.

  3. #3
    Join Date
    Apr 2003
    Posts
    176
    It's goint to be through VB.What data type i should use to store that file.

  4. #4
    Join Date
    Aug 2003
    Location
    Kingston, Ontario
    Posts
    106
    The SQL field can be Text or Image. In your application add a reference to Microsoft ActiveX Data Library 2.5 (or later).

    Then use the following to load the Word file into your SQL Table

    Code:
    Dim ado as New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim mStream as New ADODB.Stream
    
    ado.ConnectionString = "however you connect"
    ado.Open
    
    sql = "SELECT ID, MyDoc FROM MyTable Where 1=2"
    rs.Open sql, ado, adOpenKeyset, adLockPessimistic
    rs.AddNew
    
    ' Load the image into the DB field
    
    Set mStream = New ADODB.Stream
    mStream.Type = adTypeBinary
    mStream.Open
    mStream.LoadFromFile "My Word Document.doc"
    rs.Fields("MyDoc").Value = mStream.Read
    
    rs.Close
    ado.Close
    
    Set rs = Nothing
    Set ado = Nothing
    Set mStream = Nothing
    There are many ways to do this but this one works for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •