Link to home
Start Free TrialLog in
Avatar of T0masz
T0masz

asked on

adoquery (mysql) and inserting blob from file

I found this online but i cant get ParamByName to work...
I basicly want to load a file into blob (in mysql)


SQL.Add('insert into zbClientCommImg ');
SQL.Add('(CallCtr, ImgSubj, ImgUploadDT, ImgFileName, CommImg) ');
SQL.Add('VALUES(:VarCID, :VarSubj, :VarDT, :VarFileName, :VarBLOB)');

ParamByName('VarCID').AsInteger := nCallID;
ParamByName('VarSubj').AsString := sSubject;
ParamByName('VarDT').AsDate := Date;
ParamByName('VarFileName').AsString := ExtractFileName(sFileName);
ParamByName('VarBLOB').LoadFromFile(sFileName, ftBlob);

Thanks
Tom
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Hello Tom

  I think you are using AdoQuery, so ParamByName method is part of Parameters property so use this for using parameters

Parameters.ParamByName('VarCID').AsInteger := nCallID;

Regards,
Mohammed
SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mnasman you are right, I forgot about the Parameters, but I think it will work: Parameters.ParamByName('VarCID').VALUE

  with ADOQuery1.Parameters do
  begin
    ParamByName('VarCID').Value := nCallID;
    ParamByName('VarSubj').Value := sSubject;
    ParamByName('VarDT').Value := TDateTime(Date); // or TDate(Date); it depends on the field's type declaration
    ParamByName('VarFileName').Value := ExtractFileName(sFileName);
    TBLOBField(ParamByName('VarBLOB')).LoadFromFile(sFileName, ftBlob);
  end;
esoftbg , you are right

But there's no need to type casting the parameter to TBLobField, and if you do so, it will require one argument only

 with ADOQuery1.Parameters do
  begin
    ParamByName('VarCID').Value := nCallID;
    ParamByName('VarSubj').Value := sSubject;
    ParamByName('VarDT').Value := TDateTime(Date);
    ParamByName('VarFileName').Value := ExtractFileName(sFileName);
    ParamByName('VarBLOB').LoadFromFile(sFileName,ftBlob);
  end;
Thanks mnasman !