我在客户端取出Blob字段的数据已经实现了,可是在客户端向数据库中增加新记录时却无法实现,
Blob字段的内容没有保存到数据库中,程序执行没有报错,但重新取出后数据量为0,为什么?
Delphi5.0 + SQL server 7.0
代码如下:
procedure TfrmLoadTemplate.OpenDocandSaveClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
FileStream: TFileStream;
ClientBlobStream: TClientBlobStream;
begin
if OpenDialog1.Execute then
begin
FileStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
with cdsTemplatedo
begin
Close;
Open;
Append;
FieldByName('Filename').AsString:=GetFileName(Opendialog1.Filename);
FieldByName('Extname').AsString:=ExtractFileExt(Opendialog1.Filename);
FieldByName('Filepath').AsString:=Opendialog1.Filename;
ClientBlobStream := TClientBlobStream.Create(FieldByName('Filecontent') as TBlobField, bmWrite);
MemSize := FileStream.Size;
Inc(MemSize);
//Make room for the buffer's null terminator.
Buffer := AllocMem(MemSize);
//Allocate the memory.
try
ClientBlobStream.Seek(0, soFrombegin
ning);
//Seek 0 bytes from the stream's end point
FileStream.Seek(0, soFrombegin
ning);
//Seek 0 bytes from the stream's end point
FileStream.Read(Buffer^,MemSize);
ClientBlobStream.Write(Buffer^,MemSize);
Post;
ApplyUpdates(-1);
finally
FreeMem(Buffer);
FileStream.Free;
ClientBlobStream.Free;
end;
end;
end;
end;