Page 1 of 1

Error with image field

Posted: Thu 15 Mar 2012 22:49
by Susianto
Environment :
Delphi7, UNIDAC 4.1.5 for Delphi 7, SQL Server 2008 R2

Before using UNIDAC, i'm using ADO Connection

sSQL := 'INSERT INTO Customer VALUES ( :pCode, :pPhoto )';
with qryTemp do
begin
close;
SQL.Text := sSQL;
Parameters.ParamByName('pCode').Value := edtCode.Text;
if Image1.Picture.Graphic nil then
Parameters.ParamByName('pPhoto').Assign(Image1.Picture.Graphic)
else
Parameters.ParamByName('pPhoto').Value := NULL;
ExecSQL;
end;

After using UNIDAC,

sSQL := 'INSERT INTO Customer VALUES ( :pCode, :pPhoto )';
with qryTemp do
begin
close;
SQL.Text := sSQL;
ParamByName('pCode').Value := edtCode.Text;
if Image1.Picture.Graphic nil then
ParamByName('pPhoto').Assign(Image1.Picture.Graphic)
else
ParamByName('pPhoto').Value := NULL;
ExecSQL;
end;

Error occur in the statement
ParamByName('pPhoto').Assign(Image1.Picture.Graphic)

what's wrong with my code ?
Thanks for your respond.

Posted: Fri 16 Mar 2012 09:04
by Susianto
the error message is "Data type is not supported"

Posted: Fri 16 Mar 2012 10:21
by AndreyZ
Hello,

To solve the problem, you should set the DescribeParams specific option to True and prepare your query. Here is a correct code:

Code: Select all

sSQL := 'INSERT INTO Customer VALUES ( :pCode, :pPhoto )';
with qryTemp do
begin
  Close;
  SpecificOptions.Values['DescribeParams'] := 'True';
  SQL.Text := sSQL;
  Prepare;
  ParamByName('pCode').Value := edtCode.Text;
  if Image1.Picture.Graphic  nil then
    ParamByName('pPhoto').Assign(Image1.Picture.Graphic)
  else
    ParamByName('pPhoto').Value := NULL;
  ExecSQL;
end;

Posted: Fri 16 Mar 2012 10:39
by Susianto
Great. it works.
Thanks so much ;-)

Posted: Fri 16 Mar 2012 10:47
by AndreyZ
Feel free to contact us if you have any further questions about UniDAC.