title: Saving and loading jpeg images to database not working DELPHI
body: <p>I'm trying to make a program that saves images in a database. I've pulled together some info on the net and wrote up code that I think is supposed to work, but fails in a completely unique way on either side (the saving and the loading).</p>
  
  <p>Here's my code, could you tell me what I'm doing wrong?</p>
  
  <p>Load from Database, gives me a memory address access violation error:</p>
  
  <pre><code>    procedure TfrmMain.btnAddPickT4Click(Sender: TObject);
      var
        S : TMemoryStream;
        ikode : integer;
      begin
  
        if cbxDeelnemerT4.ItemIndex &lt; 0 then
        begin
          MessageDlg('Kies asseblief ''n deelnemer!',mtInformation,[mbOK],1);
          Exit;
        end;
  
        if OpenPictureDialog1.Execute then
          if FileExists(OpenPictureDialog1.FileName) then
            Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName)
          else
            MessageDlg('Die lêer bestaan nie!',mtError,[mbOK],1);
  
        ikode := cbxDeelnemerT4.ItemIndex + 1;
        S := TMemoryStream.Create;
        ADOQuery1.Close;
        ADOQuery1.SQL.Text := 'SELECT * FROM DEELNEMERS WHERE Kode = '+inttostr(ikode);
        ADOQuery1.Open;
        try
          Image1.Picture.Graphic.SaveToStream(S);
          S.Position := 1;
          ADOQuery1.Insert;
          TBLobfield(ADOQuery1.FieldByName('Foto')).LoadFromStream(S);
        finally
          S.Free;
        end;
  
  
      end;
  </code></pre>
  
  <p>Saving to the database. This code doesn't give an error as such, but it just doesn't save the image to the database:</p>
  
  <pre><code>procedure TfrmMain.btnOpenProfileT4Click(Sender: TObject);
  var
    S : TMemoryStream;
    ikode : integer;
  begin
  
      ikode := cbxDeelnemerT4.ItemIndex + 1;
    S := TMemoryStream.Create;
    ADOQuery1.Close;
    ADOQuery1.SQL.Text := 'SELECT * FROM DEELNEMERS WHERE Kode = '+inttostr(ikode);
    ADOQuery1.Open;
    try
      TBlobField(ADOQuery1.FieldByName('Foto')).SaveToStream(S);
      S.Position := 0;
      Image1.Picture.Graphic.LoadFromStream(S);
  
    finally
     s.Free;
    end;
  
  end;
  </code></pre>