Access SQL Server Database with ADO Controls

xiaoxiao2021-03-06  32

Access SQL Server database images with ADO controls, see the data discovery is basically aimed at BMP files (the mass growth database size), but found ★ eagletian ★ master translation of ADO English technical documentation, involving data inventory JPEG files Key technology, test in Win98 SQL Server desktop version, good operation, is now disclosed in the source code as follows:

Unit unit1;

Interface

Uses

Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs,

ExtCtrls, Dbctrls, Grids, DBGRIDS, DB, ADODB, JPEG, Stdctrls, DBTABLES

{Must use the USES JPEG unit, enable storage JPG file format}

Type

TFORM1 = Class (TFORM)

DataSource1: TDataSource;

Adoquery1: TadoQuery;

DBGRID1: TDBGRID;

DBNAVIGATOR1: TDBNAVIGATOR;

Image1: timage;

SaveButton: tbutton;

Showbutton: tbutton;

OpenDialog1: TopEndialog;

AdoQuery1ID: Tintegerfield;

Adoquery1Pic: TBLOBFIELD;

Procedure SaveButtonClick (Sender: TOBJECT);

Procedure ShowButtonClick (Sender: TOBJECT);

Procedure DBNAVIGATOR1CLICK (Sender: Tobject; Button: TnaviGateBTN);

Private

{Private Declarations}

public

{Public declarations}

END;

VAR

FORM1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Function JPEGSTARTSINBLOB (Picfield: TBLOBFIELD): Integer;

VAR

Ghy: tadoblobstream;

Buffer: Word;

HX: String;

Begin

RESULT: = -1;

Ghy: = tadoblobstream.create (picfield, bmread);

Try

While (result = -1) and (ghy.position 1

Begin

Ghy.readbuffer (buffer, 1);

HX: = INTTOHEX (Buffer, 2);

IF HX = 'FF' THEN BEGIN

Ghy.readbuffer (buffer, 1);

HX: = INTTOHEX (Buffer, 2);

IF hx = 'd8' Then Result: = ghy.position - 2

Else if hx = 'ff' Then

ghy.position: = ghy.position-1;

End; // IF

End; // while

Finally

ghy.free

End; // Try

END;

Procedure TFORM1.SAVEBUTTONCLICK (Sender: TOBJECT);

VAR

PicStream: tadoblobstream;

Begin

Adoquery1.edit;

PicStream: = tadoblobstream.create (TBLOBFIELD (AdoQuery1.fields [1]), BMWRITE

if Form1.Opendialog1.execute THEN

Begin

PICSTream.LoadFromFile (OpenDialog1.FileName);

PICSTream.position: = 0;

Adoquery1.edit;

TBLOBFIELD (AdoQuery1.fields [1]). LoadFromstream (PICSTREAM);

Adoquery1.post;

END;

END;

Procedure TFORM1.SHOWBUTTONCLICK (Sender: TOBJECT);

VAR

Ghy: tadoblobstream;

Pic: tjpegimage;

Begin

Ghy: = tadoblobstream.create (AdoQuery1PIC, BMREAD);

Try

Ghy.seek (JPEGSTARTSINBLOB (AdoQuery1Pic), SofromBeginning;

Pic: = tjpegimage.create;

Try

Pic.LoadFromstream (GHY);

Image1.picture.graphic: = Pic;

Finally

Pic.free;

END;

Finally

ghy.free

END;

END;

Procedure tForm1.dbnavigator1click (Sender: Tobject; Button: TnaviGateBTN);

Begin

IF button in [NBFirst, NbPrior, NBNext, NBLAST] THEN ShowButton.click;

END;

End.

If the BMP file to be stored in the database is stored, then the code changes to the BMP file format can be stored as follows.

Procedure TFORM1.SHOWBUTTONCLICK (Sender: TOBJECT);

VAR

Ghy: tadoblobstream;

Pic: Tbitmap;

Begin

Ghy: = tadoblobstream.create (AdoQuery1PIC, BMREAD);

Try

{Ghy.seek (JPEGSTARTSINBLOB (AdoQuery1Pic), SOFROMBEGINNING

Pic: = Tbitmap.create;

Try

Pic.LoadFromstream (GHY);

Image1.picture.graphic: = Pic;

Finally

Pic.free;

END;

Finally

ghy.free

END;

END;

转载请注明原文地址:https://www.9cbs.com/read-77285.html

New Post(0)