Use ADO controls to access SQL Server database images

Source: Internet
Author: User
You can use the ADO control to access the image of the SQLServer database. You can see that all the operations are performed on BMP files (the size of the database is greatly increased ).★Eagletian★The ADO English technical document translated by experts involves the key technologies used to access JPEG files in databases. It has passed the test in win98 + sqlserver desktop edition and runs well,

You can use the ADO control to access the SQL Server database image. You can view the data and find that the operation is basically performed on BMP files (the size of the database is greatly increased ).★Eagletian★The ADO English technical document translated by experts involves the key technologies used to access JPEG files in databases. It has passed the test in win98 + SQL server Desktop edition and runs well,

Use ADO controlsAccessSQL ServerDatabaseImageTo view the information and find that the operation is basically for the BMP fileDatabaseSize), but found★Eagletian★The ADO English technical documentation for expert translation involvesDatabaseAccessThe key technologies of JPEG files have been tested and run well in win98 + SQL server Desktop edition. The source code is published as follows:
Unit Unit1;

Interface

Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DBCtrls, Grids, DBGrids, Db, ADODB, jpeg, StdCtrls, dbtables;
{The uses jpeg unit is required to enable the storage of JPG files}
Type
TForm1 = class (TForm)
Performance1: 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 compute startsinblob (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 <ghy. Size) do
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.exe cute 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: Tsung image;
Begin
Ghy: = TADOBlobstream. Create (Adoquery1pic, bmRead );
Try
Ghy. Seek (export startsinblob (Adoquery1pic), soFromBeginning );
Pic: = tsf-image. 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.

IfDatabaseIf you want to store BMP files in procedure TForm1.showbuttonClick (Sender: TObject), you can save the operation of displaying BMP files by changing the Code as follows.
Procedure TForm1.showbuttonClick (Sender: TObject );
Var
Ghy: TADOBlobstream;
Pic: tbitmap;
Begin
Ghy: = TADOBlobstream. Create (Adoquery1pic, bmRead );
Try
{Ghy. Seek (export startsinblob (Adoquery1pic), soFromBeginning );}
Pic: = Tbitmap. Create;
Try
Pic. LoadFromStream (ghy );
Image1.Picture. Graphic: = Pic;
Finally
Pic. Free;
End;
Finally
Ghy. Free
End;
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.