数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

在Delphi中简单的存取JPEG文件到SQLServer


发布日期:2020年08月09日
 
在Delphi中简单的存取JPEG文件到SQLServer
在Delphi+Win+SqlServer 中测试通过运行良好现将思路源码公开如下

解决思路

关键在于将打开的JPEG文件动态转换为Tbitmap对象并显示在Timage对象中

将显示的图片提交到数据库中

本例中在SQLSERVER中建立了一个试例表exam(xm char()photo image)

程序源代码

unit SavePic;

interface

uses

Windows Messages SysUtils Variants Classes Graphics Controls Forms

Dialogs ExtDlgs ExtCtrls DBCtrls Grids DBGrids DB ADODB Buttons

StdCtrlsJpeg;

type

TForm = class(TForm)

SpeedButton: TSpeedButton;

ADOConnection: TADOConnection;

Table: TADOTable;

DataSource: TDataSource;

DBGrid: TDBGrid;

DBImage: TDBImage;

Image: TImage;

SpeedButton: TSpeedButton;

OpenPictureDialog: TOpenPictureDialog;

Label: TLabel;

Label: TLabel;

Edit: TEdit;

SpeedButton: TSpeedButton;

procedure SpeedButtonClick(Sender: TObject);

procedure SpeedButtonClick(Sender: TObject);

procedure SpeedButtonClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form: TForm;

implementation

{$R *dfm}

procedure TFormSpeedButtonClick(Sender: TObject);

var

bmp:TBitmap;

jpg:TJpegImage;

begin

OpenPictureDialogDefaultExt:=GraphicExtension(TJpegimage);

if OpenPictureDialogExecute then

begin

bmp:=TBitmapCreate;

jpg:=TJpegImageCreate;

try

jpgLoadFromFile(OpenPictureDialogFileName);

bmpAssign(jpg);

ImagePictureBitmapAssign(bmp);

finally

jpgFree;

bmpFree;

end;

end;

end;

procedure TFormSpeedButtonClick(Sender: TObject);

begin

tableOpen;

tableinsert;

tablefieldbyname(xm)asstring:=EditText;

tableFieldByName(photo)Assign(ImagePicture);

tablepost;

tableRefresh;

end;

end

上一篇:FLASH存储U盘数据恢复技术详解

下一篇:Delphi中DBGrid中行的定位及着色实现