I am trying to open a picture in my data base

Frankenfich used Ask the Experts™
Hello i am trying to open a picture that is in the ms database. Everything links fine the data base shows all the information. Except when i press on the button to open the picture associated with the Name of the animal.
Please can someone help ?
 TFrmMammals.Button1Click(Sender: TObject);
 S : TMemoryStream ;
 graphic : TGraphic ;
 GraphicType : String ;


   ADOQuery1.Close   ;
   ADOQuery1.SQL.Text := 'select Male from Mammals where EnglishName = ''' + DBLookupComboBox1.Text + ''''  ;
     ADOQuery1.Open    ;

   S := TMemoryStream.Create;
   S.Position := 0 ;

    GraphicType := ADOQuery1.fieldbyName('Male').AsString ;

   GraphicType = 'BNP'
 graphic := TBitmap.Create;

 ADOQuery1.fieldbyName('Male').AsString := 'Bnp' ;
 If GraphicType = 'Jpg'
  graphic := TJPEGImage.Create

    S.free ;
   end ;

 ADOQuery1.fieldbyName('Male').AsString := 'Bnp' ;
This is where the error is and it states class Edatabase error with message ' adoQuery : Dataset not in edit or insert mode'.
Kind regards
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Oracle dba
Top Expert 2009
I'm not sure what graphic type a "BNP" is
but i do know of a type called: BMP, also known as BITMAP
you messed up the graphic type, or is that a typo ?

next, please try and indent correctly
it makes the code more readable

and when you add code, select it and use the Code in the editor
it'll move the code into a small window within your question
and format it a little

next, you'll need to understand directions
imagine on the Left is your database, on the Right is your app

Going from Left to Right is called selecting from the database (or reading)
Going from Right to Left is called inserting/updating the database (or writing)

you've got the directions messed up
here you are reading =
GraphicType := ADOQuery1.fieldbyName('Male').AsString ;

Here you are writing to the database, without setting it in edit mode first
 ADOQuery1.fieldbyName('Male').AsString := 'Bnp' ;
because you didn't set the query in editmode, you get the error

are you aware your 'BNP' and 'Bnp' are different in case ?
This will potentially cause mismatches too ... besides the typo off course

are you trying to open a Bitmap or a Jpeg ?
are you sure there is only 2 types of pictures in that database ?

because of the very odd indenting in your code, it's very difficult to understand what you are doing
Geert GOracle dba
Top Expert 2009



Thanks Yes i know caps does influence change it. and in my case it will only be jpg and bitmap. Thanks for the help i will read over my coding again and edit it some more.  I am still very new in this will try and see if i can correct it

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial