Private Sub Command2_Click()
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim varPath As String
Dim strcontent As String, tmpstr As String
Dim bit() As Byte
Dim wordapp As Object
On Error GoTo errorhandler
Open "c:\jwoafilenamtmp.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tmpstr
strcontent = strcontent & tmpstr & vbCrLf
Loop
Close #1
strcontent = Mid(strcontent, 2, (Len(strcontent) - 4))
varPath = "c:\" + strcontent + ".doc"
Set wordapp = CreateObject("word.application")
cn.Open "Provider=sqloledb;Data Source=CAOFENG\CAOFENG;Initial Catalog=oatest;User Id=sa;Password="
rs.Open "select * from t_doc where Id = '" & strcontent & "'", cn, adOpenKeyset, adLockOptimistic
'下载文件
With rs
If .RecordCount <> 0 Then
bit = .Fields("content").GetChunk(0, 100000)
Open varPath For Binary As #1
Put 1, 1, bit
Close 1
With wordapp
.Documents.Add varPath
.Visible = True
End With
End If
End With
rs.Close
Exit Sub
errorhandler:
MsgBox Err.Description
End Sub
我使用的SQL SERVER,里面有ID和CONTENT两个字段,content是Image类型。用Appendchunk提交时,可以把DOC文档存入。但使用GetChunk再把它保存出来时,在getchunk处报“错误的参数号或无效的属性赋值”,请问是什么问题?请赐教!
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim varPath As String
Dim strcontent As String, tmpstr As String
Dim bit() As Byte
Dim wordapp As Object
On Error GoTo errorhandler
Open "c:\jwoafilenamtmp.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tmpstr
strcontent = strcontent & tmpstr & vbCrLf
Loop
Close #1
strcontent = Mid(strcontent, 2, (Len(strcontent) - 4))
varPath = "c:\" + strcontent + ".doc"
Set wordapp = CreateObject("word.application")
cn.Open "Provider=sqloledb;Data Source=CAOFENG\CAOFENG;Initial Catalog=oatest;User Id=sa;Password="
rs.Open "select * from t_doc where Id = '" & strcontent & "'", cn, adOpenKeyset, adLockOptimistic
'下载文件
With rs
If .RecordCount <> 0 Then
bit = .Fields("content").GetChunk(0, 100000)
Open varPath For Binary As #1
Put 1, 1, bit
Close 1
With wordapp
.Documents.Add varPath
.Visible = True
End With
End If
End With
rs.Close
Exit Sub
errorhandler:
MsgBox Err.Description
End Sub
我使用的SQL SERVER,里面有ID和CONTENT两个字段,content是Image类型。用Appendchunk提交时,可以把DOC文档存入。但使用GetChunk再把它保存出来时,在getchunk处报“错误的参数号或无效的属性赋值”,请问是什么问题?请赐教!
提醒一下,你还从来没有从里面取出来过,又怎么知道已经保存进去了呢?说不定根本就没有保存进数据库。所以你用上面的函数时就出错了。