AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Datein in MS SQL speichern

Ein Thema von Andidreas · begonnen am 12. Sep 2013 · letzter Beitrag vom 13. Sep 2013
 
Benutzerbild von Andidreas
Andidreas

Registriert seit: 27. Okt 2005
1.110 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#10

AW: Datein in MS SQL speichern

  Alt 13. Sep 2013, 11:25
So... Ich habs jetzt hinbekommen...

Da das ganze wie gesagt Neuland ist für mich, würd mich Eure Meinung dazu (also zu meiner Lösung) interessieren:

MS SQL Tabelle (quick & dirty angelegt zum Testen):
Code:
Create Table [mailsolution].[dbo].[mailsolution.attachments]
(
AttachmentName varchar(255),
AttachmentExt varchar(25),
AttachmentBlob varbinary(max)
)

Upload in MS SQL Tabelle
Delphi-Quellcode:
//******************************************************************************
// OnClick btn_upload *
//******************************************************************************

procedure Tmain_form.btn_uploadClick(Sender: TObject);

var
ms : TMemoryStream;

begin

  Try
    ms := TMemoryStream.Create;
    ms.LoadFromFile(edt_attachmentpath.Text);

    Try
      With (dmunidb.UniDB_Query1) Do
      Begin
        Active := False;
        SQL.Clear;
        SQL.Add(' Insert Into "mailsolution.Attachments" ');
        SQL.Add(' (AttachmentName, AttachmentExt, AttachmentBlob) ');
        SQL.Add(' Values(:AttachmentName, :AttachmentExt, :AttachmentBlob) ');
        ParamByName('AttachmentName').AsString := 'Test';
        ParamByName('AttachmentExt').AsString := '.pdf';
        ParamByName('AttachmentBlob').SetBlobData(ms.Memory, ms.Size);
        ExecSQL;
      End;
    Except
      On E:Exception Do
      Begin
        MessageDlg(E.Message, mtError, [mbOK], 0);
      End;
    End;
  Finally
    ms.Free;
  End;

end;
Download aus MS SQL Tabelle:
Delphi-Quellcode:
//******************************************************************************
// OnClick btn_download *
//******************************************************************************

procedure Tmain_form.btn_downloadClick(Sender: TObject);

var
ts: TStream;
ms: TMemoryStream;

begin

  Try
    With (dmunidb.UniDB_Query1) Do
    Begin
      Active := False;
      SQL.Clear;
      SQL.Add(' Select * From "mailsolution.Attachments" ');
      ExecSQL;
    End;
  Except
    On E:Exception Do
    Begin
      MessageDlg(E.Message, mtError, [mbOK], 0);
    End;
  End;

   Try
     ts := TStream.Create;
     ts := dmunidb.UniDB_Query1.CreateBlobStream(dmunidb.UniDB_Query1.Fieldbyname('AttachmentBlob'),bmRead);
     ms := TMemoryStream.Create;
     ms.LoadFromStream(ts);
     ms.SaveToFile(edt_savepath.Text);
   Finally
     ts.Free;
     ms.Free;
   End;

end;
Ein Programmierer Programmiert durchschnittlich 15 Code Zeilen pro Tag
Wir sind hier doch nicht bei SAP!!!

Aber wir habens bald
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:00 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz