Error with image field

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Susianto
Posts: 3
Joined: Thu 15 Mar 2012 22:23

Error with image field

Post by Susianto » Thu 15 Mar 2012 22:49

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.

Susianto
Posts: 3
Joined: Thu 15 Mar 2012 22:23

Post by Susianto » Fri 16 Mar 2012 09:04

the error message is "Data type is not supported"

AndreyZ

Post by AndreyZ » Fri 16 Mar 2012 10:21

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;

Susianto
Posts: 3
Joined: Thu 15 Mar 2012 22:23

Post by Susianto » Fri 16 Mar 2012 10:39

Great. it works.
Thanks so much ;-)

AndreyZ

Post by AndreyZ » Fri 16 Mar 2012 10:47

Feel free to contact us if you have any further questions about UniDAC.

Post Reply