SQL2000 用image类型的字段
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
Database1: TDatabase;
Query1: TQuery;
Button1: TButton;
Button2: TButton;
Query1liu: TBlobField;
Query1name: TStringField;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//将文件变成流,然后保存到数据库当中
procedure TForm1.Button1Click(Sender: TObject);
var
s:tstream;
begin
s:=tfilestream.Create('e:/pic.rar',fmopenread);
try
with adoquery1 do
begin
sql.Clear;
sql.Add('insert into liu (name,liu) values
a,:b)');
parameters.ParamByName('a').Value:=2;
parameters.ParamByName('b').LoadFromStream(s,ftblob);
execsql;
end;
finally
s.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var mypath,mypassw:string;
begin
mypath:='';
mypassw:='';
ADOQuery1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
MyPath+'db2.mdb;Jet OLEDB
atabase Password='+
MyPassW+';Persist Security Info=False';
end;
//将数据流从数据库中取出来,保存成文件
procedure TForm1.Button2Click(Sender: TObject);
begin
with adoquery1 do
begin
sql.Clear;
sql.Text:='select name,liu from liu';
open;
tblobfield(fieldbyname('liu')).SaveToFile('e:/lizi/temp/temp.asp');
end;
adoquery1.Close;
end;
end.