ntext类型的字段。我想把execl,word等文件保存到这个字段里,怎么实现读取?
解决方案 »
- Webbrowser自动获取网络的本地天气信息
- 用Setup Factory打包后,依然能打开安装之后的软件编辑?
- 使用adox建立数据库文件遇到的小问题?100分
- 急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 我的网络是通的,但使用inet控件时,时不时出现“请求超时”的错误。如何让软件在出现这种错误时仍然工作?
- 关于WEBBROWSER的关闭??(呵,在线等,解决送分)
- VB窗体尺寸怎么样计算的?
- 关于MSFlexGrid的问题!
- 急~程序总是死机
- 探讨!FTP传输编程 whit VB6
- 如何判断自定义控件(ActiveX控件)是运行在设计环境还是运行环境?好多ActiveX不让在设计环境使用,他们是怎么做到的?
- 无法找到符合要求的记录
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER"
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call FileToBlob(rs.Fields("Image"), FileName, FileLen(FileName))
rs.UpdateBatch adAffectCurrent
End SubPrivate Sub FileToBlob(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn't support the GetChunk method."
End If
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = LOF(fnum)
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
ReDim tmp(1 To bytes) As Byte
Get #1, , tmp
fld.AppendChunk tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End SubVB把文件从IMAGE字段中读到文件中。Sub loadpic(IndexNumber As Long)
Dim DcnNWind As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
DcnNWind.CursorLocation = adUseClient
DcnNWind.Open "Provider=SQLOLEDB.1;Integrated Security=SSI;Persist Security Info=False;Initial Catalog=CUSTOM;Data Source=SERVER"
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "CustomInfo", DcnNWind, , adCmdTable
rs.Move (IndexNumber)
Call BlobToFile(rs.Fields("Image"), "c:\windows\temp\tmp.bmp", rs.Fields("Image").ActualSize)
End SubPrivate Sub BlobToFile(fld As ADODB.Field, FileName As String, Optional ChunkSize As Long )
Dim fnum As Integer, bytesLeft As Long, bytes As Long
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "Field doesn't support the GetChunk method."
End If
If Dir$(FileName) <> "" Then Kill FileName
fnum = FreeFile
Open FileName For Binary As fnum
bytesLeft = fld.ActualSize
Do While bytesLeft
bytes = bytesLeft
If bytes > ChunkSize Then bytes = ChunkSize
tmp = fld.GetChunk(bytes)
Put #fnum, , tmp
bytesLeft = bytesLeft - bytes
Loop
Close #fnum
End Sub
答:读取见上面代码,也许要改一点。取出来后,存储在Temp文件夹中,然后用Shell。Public Function ShellOpenFile(sCorrectPath As String, sFilename As String, lHwnd As Long) As Long'-- Open file through associated application ShellOpenFile = ShellExecute(lHwnd, "open", sFilename, vbNullString, sCorrectPath, SW_SHOWNORMAL)End Function
sFilename = lvFiles.SelectedItem.Text
ShellOpenFile vbNullString, strTempDir & sFilename, lvFiles.hWnd