I am trying to open a picture in my data base

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);
 Var
 S : TMemoryStream ;
 graphic : TGraphic ;
 GraphicType : String ;


begin

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


   S := TMemoryStream.Create;
   Try
   TBlobField(ADOQuery1.FieldByName('Male')).SaveToStream(S);
   S.Position := 0 ;

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

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

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

   try
    Image1.Picture.Assign(graphic);
    finally
    graphic.Free;
    S.free ;
    end;
   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
Frank
FrankenfichAsked:
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.

Geert GOracle dbaCommented:
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
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
Geert GOracle dbaCommented:
0
FrankenfichAuthor Commented:
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
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.