access数据库存储长文本

任叔 2001-05-29 08:48:00
我要用DAO(注意不是ADO)的方式连接access数据库,其中一个字段要存储较大的文本,字段类型用memo的64k不够用,似乎只能用OLE对象类型了,但如何用OLE对象类型存储文本呢?
...全文
410 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
funing 2001-06-01
  • 打赏
  • 举报
回复
关注
任叔 2001-06-01
  • 打赏
  • 举报
回复
zhang_hua268 2001-06-01
  • 打赏
  • 举报
回复
guanzhu
任叔 2001-06-01
  • 打赏
  • 举报
回复
greenivy 2001-06-01
  • 打赏
  • 举报
回复
Option Explicit

'AppendChunk and GetChunk Methods Example

'This example uses the AppendChunk and GetChunk methods to fill an OLE object field with data from another record, 32K at a time. In a real application, one might use a procedure like this to copy an employee record (including the employee's photo) from one table to another. In this example, the record is simply being copied back to same table. Note that all the chunk manipulation takes place within a single AddNew-Update sequence.

Sub AppendChunkX()

Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim rstEmployees2 As Recordset

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

' Open two recordsets from the Employees table.
Set rstEmployees = _
dbsNorthwind.OpenRecordset("Employees", _
dbOpenDynaset)
Set rstEmployees2 = rstEmployees.Clone

' Add a new record to the first Recordset and copy the
' data from a record in the second Recordset.
With rstEmployees
.AddNew
!FirstName = rstEmployees2!FirstName
!LastName = rstEmployees2!LastName
CopyLargeField rstEmployees2!Photo, !Photo
.Update

' Delete new record because this is a demonstration.
.Bookmark = .LastModified
.Delete
.Close
End With

rstEmployees2.Close
dbsNorthwind.Close

End Sub

Function CopyLargeField(fldSource As Field, _
fldDestination As Field)

' Set size of chunk in bytes.
Const conChunkSize = 32768

Dim lngOffset As Long
Dim lngTotalSize As Long
Dim strChunk As String

' Copy the photo from one Recordset to the other in 32K
' chunks until the entire field is copied.
lngTotalSize = fldSource.FieldSize
Do While lngOffset < lngTotalSize
strChunk = fldSource.GetChunk(lngOffset, conChunkSize)
fldDestination.AppendChunk strChunk
lngOffset = lngOffset + conChunkSize
Loop

End Function
任叔 2001-06-01
  • 打赏
  • 举报
回复
任叔 2001-05-31
  • 打赏
  • 举报
回复
任叔 2001-05-31
  • 打赏
  • 举报
回复
任叔 2001-05-30
  • 打赏
  • 举报
回复
我是要把很多文件放到一个数据库里,要是只放文件名就没必要用数据库了,现在只是想知道怎么用DAO添加包括OLE对象字段的记录
cqq_chen 2001-05-30
  • 打赏
  • 举报
回复
最简单的方法是在数据库中只存文本文件的文件名就可以。
任叔 2001-05-30
  • 打赏
  • 举报
回复
谢谢,不过我要用DAO,而不是ADO
yangsaibing 2001-05-30
  • 打赏
  • 举报
回复
该例子从文件读出二进制数据流,并写入ACCESS数据库

Dim TempFileName As String
Dim adoConnection As New ADODB.Connection
Dim adoRecordset As New ADODB.Recordset
TempFileName ="c:\test.bmp"

adoConnection.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\test.mdb"
adoRecordset.Open "SELECT PIC FROM pictable", adoConnection, adOpenKeyset, adLockOptimistic ', adCmdTable
adoRecordset.AddNew
Dim adoStream As New ADODB.Stream
adoStream.Type = adTypeBinary
adoStream.Open
adoStream.LoadFromFile TempFileName
'将二进制文件写入大字段:
adoRecordset.Fields(0).AppendChunk adoStream.Read
adoRecordset.update
set adoRecordSet = Nothing
Set adoStream = Nothing
任叔 2001-05-29
  • 打赏
  • 举报
回复
不是很大,但可能会超过64k,所以字段用memo不行
cqq_chen 2001-05-29
  • 打赏
  • 举报
回复
你的文本大的什么程度呢?
任叔 2001-05-29
  • 打赏
  • 举报
回复
任叔 2001-05-29
  • 打赏
  • 举报
回复
DAO中Memo是1.2GB,但Access数据库的Memo是64K,所以只能用OLE对象了,但我不知道怎样把文本存进去
guest 2001-05-29
  • 打赏
  • 举报
回复
bin保存文件
zzy198 2001-05-29
  • 打赏
  • 举报
回复
memo字段好像可以容纳大于64k的文本。

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧