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
T0maszAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:
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
0
esoftbgCommented:
 with ADOQuery1 do
  begin
    ParamByName('VarCID').Value := nCallID;
    ParamByName('VarSubj').Value := sSubject;
    ParamByName('VarDT').Value := TDateTime(Date); // or TDate(Date); it depends on the field's declaration
    ParamByName('VarFileName').Value := ExtractFileName(sFileName);
    TBLOBField(ParamByName('VarBLOB')).LoadFromFile(sFileName, ftBlob);
  end;
0
Mohammed NasmanSoftware DeveloperCommented:
esoftbg, that's will not work too

for AdoQuery it should be like

with ADOQuery1.Parameters do
  begin
    ParamByName('VarCID').AsInteger := nCallID;
    ParamByName('VarSubj').AsString := sSubject;
    ParamByName('VarDT').AsDate := Date;
    ParamByName('VarFileName').AsString := ExtractFileName(sFileName);
    ParamByName('VarBLOB').LoadFromFile(sFileName);
  end;

in addition the LoadFromFile method should take one parameter only

Tom, which components do you use for accessing MySql?
also if not one of the comments worked for you, you should say that, don't wait for more comments without explaining more ;), that's will help all to guide you to the answer faster

Regards,
Mohammed
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

esoftbgCommented:
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;
0
Mohammed NasmanSoftware DeveloperCommented:
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;
0
esoftbgCommented:
Thanks mnasman !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.