?
Solved

adoquery (mysql) and inserting blob from file

Posted on 2004-11-07
6
Medium Priority
?
1,284 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:T0masz
  • 3
  • 3
6 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12516602
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
 
LVL 12

Assisted Solution

by:esoftbg
esoftbg earned 800 total points
ID: 12518161
 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
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 1200 total points
ID: 12521131
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Expert Comment

by:esoftbg
ID: 12521282
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
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12521383
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12521444
Thanks mnasman !
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question