将word、excel、pdf文件存入数据库

怎么给你例子,所有代码不过20来行,核心代码不过数行

1、打开文件
  with TOpenDialog.Create(Self) do
  try
    if Execute then
    begin
      OleContainer.CreateObjectFromFile(FileName,False);
      OleContainer.DoVerb(OleContainer.PrimaryVerb);
    end;
  finally
    Free;
  end;

2、保存到数据库中
var
Stream: TStream;

        ADOQury.Insert;
        ADOQury.FieldByName('FILEIDNO').AsString:='0001';
        Stream:=ADOQury.CreateBlobStream(ADOQury.FieldByName('FILEBODY'), bmWrite);
        try
          OleContainer.SaveToStream(Stream);
        finally
          Stream.Free;
        end;
        ADOQury.Post;

3、打开数据表察看文件
var
  Stream: TStream;

        Stream:=ADOQury.CreateBlobStream(ADOQury.FieldByName('FILEBODY'), bmRead);
        try
          OleContainer.LoadFromStream(Stream);
        finally
          Stream.Free;
        end;
        OleContainer.DoVerb(ovPrimary); 

你可能感兴趣的:(将word、excel、pdf文件存入数据库)