delphi image图片如何插入到数据库
1个回答
2013-12-03
展开全部
procedure TForm1.Button1Click(Sender: TObject);
var Conn:TAdoConnection;
strm:TStream;
qry:TAdoQuery;
begin
strm:=TMemoryStream.Create;
image1.Picture.Bitmap.SaveToStream(strm);
conn:=TAdoConnection.Create(nil);
conn.ConnectionString:='provider=Microsoft.Jet.OleDB.4.0;Data Source=d:\a.mdb';
conn.LoginPrompt:=false;
conn.Open;
qry:=TAdoQuery.Create(nil);
qry.SQL.Text := 'insert into test(pic) values (:pic)';
qry.Connection :=conn;
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
qry.ExecSQL;
conn.Close;
conn.Free;
qry.Free;
strm.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var Conn:TAdoConnection;
strm:TStream;
qry:TAdoQuery;
begin
conn:=TAdoConnection.Create(nil);
conn.ConnectionString:='provider=Microsoft.Jet.OleDB.4.0;Data Source=d:\a.mdb';
conn.LoginPrompt:=false;
conn.Open;
qry:=TAdoQuery.Create(nil);
qry.SQL.Text := 'select pic from test';
qry.Connection :=conn;
qry.Open ;
strm:=qry.CreateBlobStream(qry.FieldByName('pic'),bmRead);
image2.Picture.Bitmap.LoadFromStream(strm);
qry.Close;
conn.Close;
conn.Free;
qry.Free;
strm.Free;
end;
procedure TForm1.FormShow(Sender: TObject);
var jpg:TJpegImage;
bmp:TBitMap;
begin
jpg:=TJpegImage.Create;
bmp:=TBitMap.Create;
jpg.LoadFromFile('C:\Users\Administrator\Pictures\psu.jpg');
bmp.Assign(jpg);
image1.Picture.Bitmap:=bmp;
end;
var Conn:TAdoConnection;
strm:TStream;
qry:TAdoQuery;
begin
strm:=TMemoryStream.Create;
image1.Picture.Bitmap.SaveToStream(strm);
conn:=TAdoConnection.Create(nil);
conn.ConnectionString:='provider=Microsoft.Jet.OleDB.4.0;Data Source=d:\a.mdb';
conn.LoginPrompt:=false;
conn.Open;
qry:=TAdoQuery.Create(nil);
qry.SQL.Text := 'insert into test(pic) values (:pic)';
qry.Connection :=conn;
qry.Parameters.ParseSQL(qry.SQL.Text ,true);
qry.Parameters.ParamByName('pic').LoadFromStream(strm,ftBlob);
qry.ExecSQL;
conn.Close;
conn.Free;
qry.Free;
strm.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var Conn:TAdoConnection;
strm:TStream;
qry:TAdoQuery;
begin
conn:=TAdoConnection.Create(nil);
conn.ConnectionString:='provider=Microsoft.Jet.OleDB.4.0;Data Source=d:\a.mdb';
conn.LoginPrompt:=false;
conn.Open;
qry:=TAdoQuery.Create(nil);
qry.SQL.Text := 'select pic from test';
qry.Connection :=conn;
qry.Open ;
strm:=qry.CreateBlobStream(qry.FieldByName('pic'),bmRead);
image2.Picture.Bitmap.LoadFromStream(strm);
qry.Close;
conn.Close;
conn.Free;
qry.Free;
strm.Free;
end;
procedure TForm1.FormShow(Sender: TObject);
var jpg:TJpegImage;
bmp:TBitMap;
begin
jpg:=TJpegImage.Create;
bmp:=TBitMap.Create;
jpg.LoadFromFile('C:\Users\Administrator\Pictures\psu.jpg');
bmp.Assign(jpg);
image1.Picture.Bitmap:=bmp;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询