数据库如何插入图片?!解决完后立刻给分!(100分)

  • 主题发起人 主题发起人 woyaoying
  • 开始时间 开始时间
“最后一个问题,如果嵌入MP3,你们说好做吗? ”
放心,放置什么样的文件都可以,打印模板也行。
 
楼上的别光说啊,写个demo看看如何?
 
楼主,写demo比较累,只能给你一个思路。
读操作:
Stream:=TadoblobStream.Create(qry.fieldbyname('FileBlob') as TBlobField, bmRead);
写操作(摘自delphi帮助文件):
Writes data from a memory buffer to a BLOB field object.

function Write(const Buffer; Count: Longint): Longint; override;

Description

Use Write to copy data from a PChar (or comparable) buffer in memory to the BLOB field object. Write copies data from the buffer to the current position in the BLOB field object (current position indicated by the Position property). Write copies the number of bytes specified in Count or the number of bytes remaining in the memory buffer (counting from the current position to the end), whichever is less. Write can be called multiple times during the lifetime of a TADOBlobStream, each call copying less than the total number of bytes to be copied.

Count represents the maximum number of bytes to copy in a single call to Write. Count may be less than, the same as, or greater than the number of bytes actually contained in the memory buffer. If Count is greater than the actual number of bytes present or remaining in the memory buffer, copying stops at the last byte. No penalty is incurred on exceptions generated by specifying a number greater than the actual size of the contents.

Write updates the Size property to Position + Count, and sets the Position property to the new value of Size. Thus, any data that was stored in the memory stream in the Count bytes after the current position is lost when calling Write.

After successful execution, Write returns the number of bytes copied to the BLOB field object. If the return value is less than Count, the most likely reason is that the end of the buffer was reached prior to copying the specified number of bytes.

var

P: PChar;
S: Integer;
BS: TADOBlobStream;
begin
if not (ADOTable1.State in [dsEdit, dsInsert]) then
ADOTable1.Edit;
BS := TADOBlobStream.Create(TMemoField(ADOTable1.Fields[1]), bmWrite);
try
S := Memo1.GetTextLen;
Inc(S);
P := AllocMem(S);
FillChar(P^, S, #0);
Memo1.GetTextBuf(P, S);
BS.Write(P^, S);
finally
BS.Free;
FreeMem(P, S);
end;

end;

 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
770
import
I
后退
顶部