unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, NxScrollControl, NxCustomGridControl, NxCustomGrid, NxDBGrid,
  DB, ADODB, NxDBColumns, NxColumns, StdCtrls, ExtDlgs, JPeg;

type
  TForm1 = class(TForm)
    NextDBGrid1: TNextDBGrid;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    TNxDBTextColumn1: TNxDBTextColumn;
    Button1: TButton;
    OpenPictureDialog1: TOpenPictureDialog;
    NxDBGraphicColumn1: TNxDBGraphicColumn;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure SetBlobField(Table: TADOTable; Field: TBlobField;
  Graphic: TGraphic);                                   
var
  BlobStream: TADOBlobStream;
begin
  BlobStream := TADOBlobStream.Create(Field, bmWrite);
  Graphic.SaveToStream(BlobStream);
  try
    Field.LoadFromStream(BlobStream);
  finally
    BlobStream.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  G: TGraphic;
begin
  if OpenPictureDialog1.Execute then
  begin
    ADOTable1.Edit;
    G := TJPEGImage.Create;
    TJPEGImage(G).Performance := jpBestSpeed;
    TJPEGImage(G).Scale := jsEighth;
    G.LoadFromFile(OpenPictureDialog1.FileName);
    SetBlobField(ADOTable1, TBlobField(ADOTable1.FieldByName('Image')), G);
    ADOTable1.Post; 
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ADOTable1.Append;
  ADOTable1.FieldByName('Title').AsString := 'Untitled';
  ADOTable1.Post;
end;

end.
