昨天写的Access的,把那个字段类型。。那里改改就行
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); [blue]//这里可能要改改[/blue]
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.