DELPHI ADO /ODAC 實現BLOB存取(文件大小不限制)

页面导航:首页 > 软件编程 > Delphi > DELPHI ADO /ODAC 實現BLOB存取(文件大小不限制)

DELPHI ADO /ODAC 實現BLOB存取(文件大小不限制)

来源: 作者: 时间:2016-01-21 09:33 【

通過ADO,ODAC實現文件上傳和讀取,具體代碼如下: 源代碼下載鏈接: http://download.csdn.net/download/xiechunlei8454/3875686unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes...

 

通過ADO,ODAC實現文件上傳和讀取,具體代碼如下:

 

  源代碼下載鏈接:    http://download.csdn.net/download/xiechunlei8454/3875686

 

 

 

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, Grids, ValEdit, DB, ADODB, StdCtrls, DBAccess, Ora, MemDS,

  ExtCtrls, jpeg;

 

type

  TForm1 = class(TForm)

    adc: TADOConnection;

    os1: TOraSession;

    Edit1: TEdit;

    Label1: TLabel;

    Label2: TLabel;

    Edit2: TEdit;

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    opd1: TOpenDialog;

    adq1: TADOQuery;

    oq1: TOraQuery;

    Button4: TButton;

    Button5: TButton;

    Label3: TLabel;

    Panel1: TPanel;

    img1: TImage;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  if opd1.Execute then begin

     edit2.Text:=opd1.FileName;

  end;

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  if edit1.Text='' then begin

     showmessage('Please Input Name First!');

     edit1.SelectAll;

     edit1.SetFocus;

     exit;

  end;

  if edit2.Text='' then begin

     showmessage('Please Choose File First!');

     button1.SetFocus;

     exit;

  end;

  with adq1 do begin

       close;

       sql.clear;

       sql.text:= 'select * from sfis1.c_test_t where name=:nm';

       Parameters.ParamByName('nm').Value:=edit1.Text;

       open;

       if RecordCount>0 then begin

          edit;

          fieldbyname('name').value:=edit1.Text;

          TBlobField(fieldbyname('appendex')).LoadFromFile(edit2.Text);

          post;

          close;

       end else begin

          append;

          fieldbyname('name').value:=edit1.Text;

          TBlobField(adq1.fieldbyname('appendex')).LoadFromFile(edit2.Text);

          post;

          close;

       end;

  end;

  edit1.Text:='';

  edit2.Text:='';

  showmessage('ADO SAVE OK!');

end;

 

procedure TForm1.Button3Click(Sender: TObject);

begin

  if edit1.Text='' then begin

     showmessage('Please Input Name First!');

     edit1.SelectAll;

     edit1.SetFocus;

     exit;

  end;

  if edit2.Text='' then begin

     showmessage('Please Choose File First!');

     button1.SetFocus;

     exit;

  end;

  with oq1 do begin

       close;

       sql.clear;

       sql.text:= 'select * from sfis1.c_test_t where name=:nm';

       parambyname('nm').AsString:=edit1.Text;

       open;

       if recordcount>0 then

          edit

       else

          append;

       fieldbyname('name').value:=edit1.Text;

       TBlobField(fieldbyname('appendex')).LoadFromFile(edit2.Text);

       post;

       close;

  end;

  edit1.Text:='';

  edit2.Text:='';

  showmessage('ODAC SAVE OK!');

end;

 

procedure TForm1.Button4Click(Sender: TObject);

var f1:string;

begin

  if edit1.Text='' then begin

     showmessage('Please Input Name First!');

     edit1.SelectAll;

     edit1.SetFocus;

     exit;

  end;

  if edit1.Text<>'' then begin

     with adq1 do begin

          close;

          sql.Clear;

          sql.Add('select * from sfis1.c_test_t where name=:nm');

          Parameters.ParamByName('nm').Value:=edit1.Text;

          Open;

          if recordcount>0 then begin

             f1:=extractfilepath(application.ExeName)+edit1.Text+'.JPG';

             if fileexists(f1) then

                deletefile(f1);

             Tblobfield(fieldbyname('appendex')).SaveToFile(f1);

             img1.Picture.LoadFromFile(f1);

             label3.Caption:='File Name Is: '+edit1.Text+'.JPG';

          end;

     end;

  end;

end;

 

procedure TForm1.Button5Click(Sender: TObject);

var f1:string;

begin

  if edit1.Text='' then begin

     showmessage('Please Input Name First!');

     edit1.SelectAll;

     edit1.SetFocus;

     exit;

  end;

  if edit1.Text<>'' then begin

     with oq1 do begin

          close;

          sql.Clear;

          sql.Add('select * from sfis1.c_test_t where name=:nm');

          ParamByName('nm').AsString:=edit1.Text;

          Open;

          if recordcount>0 then begin

             f1:=extractfilepath(application.ExeName)+edit1.Text+'.JPG';

             if fileexists(f1) then

                deletefile(f1);

             Tblobfield(fieldbyname('appendex')).SaveToFile(f1);

             img1.Picture.LoadFromFile(f1);

             label3.Caption:='File Name Is : '+edit1.Text+'.JPG';

          end;

     end;

  end;

 

end;

 

end.

 

摘自 xiechunlei8454的专栏

Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<