用access的ole字段存储图像具体要怎样操作啊,用loadfromFile都不行!:((20分)

  • 主题发起人 主题发起人 del520
  • 开始时间 开始时间
呵呵
试好了,VeryGood! 还是你历害!

只是想不通干嘛要通过那个剪贴板来玩两下!

分给你了!
 
[blue]我的也行,,我不是说今天搞定吗???呵可,不要分也行,学习[/blue]

代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, ADODB, StdCtrls, DBCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ADOQuery1: TADOQuery;
    btnWrite: TButton;
    Button2: TButton;
    Button3: TButton;
    DBImage1: TDBImage;
    DataSource1: TDataSource;
    DBNavigator1: TDBNavigator;
    btnRead: TButton;
    procedure btnWriteClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure btnReadClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.btnWriteClick(Sender: TObject);
var
  msMyWaveFile: TMemoryStream;
begin
  msMyWaveFile := TMemoryStream.Create;
  msMyWaveFile.LoadFromFile('c:/line.bmp');
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('insert into mytable (myole) values (:myparameter)');
    Parameters.ParamByName('myparameter').LoadFromStream(msMyWaveFile,  ftDBaseOle);
//    TBlobField(Parameters.ParamByName('myparameter')).LoadFromStream(msMyWaveFile);
   // Parameters.ParamByName('myparameter').Value := 1;
    //ShowMessage(SQL.Text);
    ExecSQL;
    Close;
  end;
  msMyWaveFile.Free;
end;

//    Parameters.ParamByName('mypara').Value := '11';
//    ShowMessage(SQL.Text);

procedure TForm1.Button2Click(Sender: TObject);
var
  msMyWaveFile: TMemoryStream;
begin
  msMyWaveFile := TMemoryStream.Create;
  msMyWaveFile.LoadFromFile('c:/line.bmp');
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('update  mytable set myole = :myparameter');

    TBlobField(Parameters.ParamByName('myparameter')).LoadFromStream(msMyWaveFile);
//    Parameters.ParamByName('myparameter').Value := 1;
    //ShowMessage(SQL.Text);
    ExecSQL;
    Close;
  end;
  msMyWaveFile.Free;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  msMyWaveFile: TMemoryStream;
begin
  msMyWaveFile := TMemoryStream.Create;
  msMyWaveFile.LoadFromFile('c:/line.bmp');
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select myole from mytable');
    Open;
    Edit;
    TBlobField(FieldByName('myole')).LoadFromStream(msMyWaveFile);
    Post;
    Close;
  end;
  msMyWaveFile.Free;
end;

procedure TForm1.btnReadClick(Sender: TObject);
var
  msFileData: TMemoryStream;
begin
  msFileData := TMemoryStream.Create;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select myole from mytable');
    Open;
    Fields[0].SetFieldType(ftDBaseOle);
    //Fields[0].OldValue;
    TBlobField(Fields[0]).SaveToStream(msFileData);

    msFileData.SaveToFile('c:/ab.bmp');



  end;
  msFileData.Free;
end;

end.
 
代码:
再贴一次。。。

更新一点的。。。去除多余的。。。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, ADODB, StdCtrls, DBCtrls, ExtCtrls;

type
  TfrmTestAccessImge = class(TForm)
    ADOQuery1: TADOQuery;
    btnWrite: TButton;
    DBImage1: TDBImage;
    DataSource1: TDataSource;
    DBNavigator1: TDBNavigator;
    btnRead: TButton;
    procedure btnWriteClick(Sender: TObject);
    procedure btnReadClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmTestAccessImge: TfrmTestAccessImge;

implementation

{$R *.DFM}

procedure TfrmTestAccessImge.btnWriteClick(Sender: TObject);
var
  msFileData: TMemoryStream;
begin
  msFileData := TMemoryStream.Create;
  msFileData.LoadFromFile('c:/line.bmp');
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('insert into mytable (myole) values (:myparameter)');
    Parameters.ParamByName('myparameter').LoadFromStream(msFileData,
      ftDBaseOle);
    ExecSQL;
    Close;
  end;
  msFileData.Free;
end;

procedure TfrmTestAccessImge.btnReadClick(Sender: TObject);
var
  msFileData: TMemoryStream;
begin
  msFileData := TMemoryStream.Create;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select myole from mytable');
    Open;
    Fields[0].SetFieldType(ftDBaseOle);
    TBlobField(Fields[0]).SaveToStream(msFileData);
    //    有一个DBImage控件在窗体上
    //    msFileData.SaveToFile('c:/ab.bmp');
  end;
  msFileData.Free;
end;

end.
 
我刚做好的,很实用,没什么深奥的东西 uses 要加jpeg啊
var
picturename,extname:string;
jpegimage:Tjpegimage;

begin
opd1.Filter:='Jpeg Image File (*.jpg)|*.JPG|Bitmaps (*.bmp)|*.BMP';
if opd1.Execute then
begin
picturename:=opd1.FileName;
extname:=ExtractfileExt(picturename);
if uppercase(extname)='.BMP' then
begin
db2.BtnClick(nbedit);
zhaopian.Picture.LoadFromFile(opd1.FileName);
end
else if (uppercase(extname)='.JPG') or (uppercase(extname)='.JPEG') then
begin
jpegimage:=Tjpegimage.Create;
try
jpegimage.loadfromfile(opd1.filename);
db2.BtnClick(nbedit);
zhaopian.Picture.Graphic.Assign(Jpegimage);
finally
jpegimage.free;
end;
end;
end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
781
import
I
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部