当前位置:编程学习 > Delphi >>

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

 

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

 

  源代易做图下載鏈接:    http://download.csdn.net/download/xiechunlei8454/3875686

 

 

 

unit Unit1;

 

inte易做图ce

 

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);

       &nb

补充:软件开发 , Delphi ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,