在SQL SERVER2000中存取WORD文档如何实现。谢谢各位!!!!!!!!

mhgk2 2004-09-29 01:02:46
在SQL SERVER2000中存取WORD文档如何实现。谢谢各位!!!!!!!!
...全文
150 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
michael2002168 2005-04-07
我 引用 Microsoft ActiveX Data Objects 2.0Library 好象不行,
因为我用了Adodc控件,使用2.0以上版本是用不了的。这该怎么办?
回复
rgwfeng2 2004-10-16
mark
回复
cqm2099 2004-10-03
Up,, 收藏
回复
vbman2003 2004-09-30
保存Word文档的字段类型改为image试试
另外,在读取文档时,TempTest.doc不能事先存在,代码修改如下:

'读取数据库中的Word文档
Private Sub cmdRead_Click()
Dim Sql As String
Sql = "select word from tb_word where id=1"
Set rs = New ADODB.Recordset
rs.Open Sql, cn, adOpenKeyset, adLockOptimistic
If Dir(App.Path & "\TempTest.doc") <> "" Then
Kill App.Path & "\TempTest.doc"
End If
Set StmWord = New ADODB.Stream
With StmWord
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write rs!Word
.SaveToFile App.Path & "\TempTest.doc"
.Close
End With
Call OpenWord(App.Path & "\TempTest.doc")
rs.Close
End Sub
回复
mhgk2 2004-09-30
执行到rs.Fields("word").Value = StmWord.Read这句就出错《多步OLE》错误
回复
lxcc 2004-09-29
上面是c#的
这是VB的
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;258038&Product=vbb
回复
lxcc 2004-09-29
http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
回复
vbman2003 2004-09-29
'** 数据库使用 ADODB.Stream 保存/读取Word文档的示例代码
'** 引用 Microsoft ActiveX Data Objects 2.5 Library 及以上版本
'** 引用 Microsoft Word 9.0 Objects Library
'** 保存Word文档的字段为word(Access数据库为OLE对象,SQL数据库为二进制数据类型)

Option Explicit
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StmWord As ADODB.Stream

'调用WORD函数
Sub OpenWord(FileName As String)
Dim WordTemps As New Word.Application
WordTemps.Documents.Add FileName, False
WordTemps.Visible = True
End Sub

'窗体载入时连接数据库
Private Sub Form_Load()
Set cn = New ADODB.Connection
cn.Open "Provider = SQLOLEDB.1;Persist Security Info = False;" & _
"User ID = sa;Password = abc;Data Source = SERVER;" & _
"Initial Catalog = youDB"
End Sub

'将Wowd文档保存到数据库
Private Sub cmdSave_Click()
Set rs = New ADODB.Recordset
rs.Open "select * from TableName", _
cn, adOpenKeyset, adLockOptimistic
Set StmWord = New ADODB.Stream
With StmWord
.Type = adTypeBinary
.Open
.LoadFromFile "F:\My Documents\test.doc"
End With
rs.AddNew
rs.Fields("word").Value = StmWord.Read
rs.Update
StmWord.Close
rs.Close
End Sub

'读取数据库中的Word文档
Private Sub cmdRead_Click()
Dim Sql As String
Sql = "select * from TableName where id=3"
Set rs = New ADODB.Recordset
rs.Open Sql, cn, adOpenKeyset, adLockOptimistic
Set StmWord = New ADODB.Stream
With StmWord
.Mode = adModeReadWrite
.Type = adTypeBinary
.Open
.Write rs!Word
.SaveToFile App.Path & "\TempTest.doc"
.Close
End With
Call OpenWord(App.Path & "\TempTest.doc")
rs.Close
End Sub
回复
danielinbiti 2004-09-29
存,取就刚好反过来
Public Function FileToDatabase(ByVal vDataField As ADODB.Field, ByVal vFileName As String)
Dim fnum As Long, bytesleft As Long, bytes As Long
Dim lSumSize As Long, lNowSize As Long
Dim tmp() As Byte

On Error GoTo ErrHandle

fnum = FreeFile
Open vFileName For Binary As fnum
bytesleft = LOF(fnum)
lSumSize = CLng(bytesleft / 8192)
Do While bytesleft
bytes = bytesleft
If bytes > 8192 Then bytes = 8192
ReDim tmp(1 To bytes) As Byte
Get #fnum, , tmp
vDataField.AppendChunk tmp
bytesleft = bytesleft - bytes
lNowSize = lNowSize + 1
Loop

Close #fnum

Exit Function
ErrHandle:
MsgBox err.Description
err.Clear
End Function
回复
jam021 2004-09-29
关注,帮你顶!
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告