How to insert image into database?
Have an IMAGE type field (should be available in SQL Server 2000):
CREATE TABLE MyTable (
ID INT PRIMARY KEY,
Picture IMAGE
)
And insert an image into it:
FDQuery1.SQL.Text := 'INSERT INTO MyTable (ID, Picture) VALUES (:ID, :Picture)';
FDQuery1.ParamByName('ID').AsInteger := 1;
FDQuery1.ParamByName('Picture').AsStream := TFileStream.Create('C:\Image.jpg', fmOpenRead);
FDQuery1.ExecSQL;
The stream created above will be released after query unpreparing, or after next value assignment.
How to display image in a TDBImage control?
Drop TDBImage control on your form with TDataSource and TFDQuery, for example. Now connect these components and setup source field for the image:
DataSource1.DataSet := FDQuery1;
DBImage1.DataSource := DataSource1;
DBImage1.DataField := 'Picture';
And query for data, for example:
FDQuery1.SQL.Text := 'SELECT Picture FROM MyTable WHERE ID = :ID';
FDQuery1.ParamByName('ID').AsInteger := 1;
FDQuery1.Open;