3.1在 Access中建立 資料 庫 BLOB.mdb,表 Graphic。結構 如 下圖 :

圖 數 據 庫 BLOB.nldb的 Gra phic表 結 構
3.2設計 界面
表單上放置組件 ADOConnection1、ADOQueryl、Imagel、Data Surce1、DBNavigator1.兩個o Tradio Button,名
稱分 別 為 rbtn BMP、rbtn JG.設P 置 ADOConnectionl的 Connection Sring連t 接 到 數 據 庫 BLOB.mdb;設 置
ADOQue~I的 Connection為 ADOConnectionl,SQL為 Select from Graphic;設 置 Data Surcel的o Data Set為
ADOQue~I,設定 DBNavigatorl的 Data Surce為o Data Source1.
大家幫忙看看這個代碼哪兒寫錯了。。。。。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DBCtrls, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Image1: TImage;
DataSource1: TDataSource;
DBNavigator1: TDBNavigator;
rbtnBMP: TRadioButton;
rbtnJPG: TRadioButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Uses JPEG
procedure TForml.FormCreate(Sender;TObject);
begin
ADOConnection1.ConnectionString:=
Provider=Microsoft.Jet.OLEDB.4.0;Data source=BLOB.accdb';
ADOConnection1.Connected:=True;
ADOQuery1.Open;
end;
{向Access資料庫保存bmp和jpg圖片的程序}
procedure TForml.SaveP.mpJpg;
begin
with TOpenDialog.Create(Self) do
begin
Filter:=bmp(*.bmp)/*.bmp/jpg(*.jpg)/*.jpg';
if Execute then
begin
AdoQuery1.First;
if FilterIndex=1 then
begin
while AdoQuery1bmp.BlobSize<>0 do begin
AdoQuery1.Next;
if AdoQuery1.Eof then AdoQuery1.Append;
end;
AdoQuery1.Edit;
TBlobField(AdoQuery1.FieldByName(bmp')).LoadFromFile
(FileName);
end;
if FilterIndex=2 then
begin
While AdoQuery1 jpeg.BlobSize<>0 do begin
AdoQuery1.Next;
If AdoQuery1 jpeg.Eof then AdoQuery1.Append;
end;
AdoQuery1.Edit;
TBlobField(AdoQuery1.FieldByName(jpeg')).Loadfrom-
File(FileName);
end;
AdoQuery1.Post;
end;
end;
end;
{顯示BMP影像的程序}
procedure TForml.DisplayBMP;
var ms: TMemoryStream;
begin
if AdoQuery1bmp.BlobSize>0 then
begin
ms :=Tmemorystream.Create;
TBlobField(AdoQuery1.FieldByName(bmp')).SaveToStream(ms);
ms.Seek(0,soFromBeginning);
Image1.Picture.Bitmap.LoadFromStream(Ms);
ms.Free;
end
else
image1.Picture := nil;
end;
{顯示JPG影像的程序}
procedure TForml.DisplayJPG;
var
jpeg:Tjpegimage;ms:TMemoryStream;
begin
if AdoQuery1 jpeg.BlobSize>0 then
begin
jpeg:=Tjpegimage.Create;
ms:=Tmemorystream.Create;
TBlobField(adoquery1. FieldByName('jpeg'))
SaveToStream(ms);
ms.Seak(0,soFromBeginning);
jpeg.LoadFromStream(ms);
image1.Picture.Assign(jpeg);
jpeg.Free;
ms.Free;
end
else
image1.Picture := nil;
end;
uj5u.com熱心網友回復:
各位大神 求修改指導轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/82131.html
標籤:數據庫相關
