Fórum salvando arquivos no SQL SERVER 2012 - URGENTE.... #473541
21/03/2014
0
Estou fazendo um teste e preciso salvar arquivo .PDF ou .ZIP dentro do Banco de Dados e depois restaura-los. Estou usando o Delphi xe3 e Banco SQL 2012 Server Enterprise. Se alguem puder me ajudar Agradeço
Represinfo Ltda
Curtir tópico
+ 0
Responder
Posts
21/03/2014
Wilton Queiroz
procedure SalvaArquivoBancoDados(dbConnection:TADOConnection;arquivo:string);
var qry:TADOQUERY;
begin
try
qry :=tadoquery.create(nil);
qry.Options.StrictUpdate :=false;
qry.connection :=dbConnection;
qry.Close;
qry.Sql.Text :='SELECT * FROM ARQUIVOS WHERE ARQUIVO='+QUOTEDSTR(ARQUIVO);
qry.Open;
if (qry.RecordCount>0) then
(qry.fieldbyname('BINARIO') as TBlobField).savetofile(Arquivo); //salvando em disco
else
begin
qry.append;
qry.fieldbyname('arquivo').asstring :=arquivo;
(qry.fieldbyname('BINARIO') as TBlobField).loadfromfile(Arquivo); //lendo do disco
qry.post;
end
finally
freeandnil(qry);
end;
var qry:TADOQUERY;
begin
try
qry :=tadoquery.create(nil);
qry.Options.StrictUpdate :=false;
qry.connection :=dbConnection;
qry.Close;
qry.Sql.Text :='SELECT * FROM ARQUIVOS WHERE ARQUIVO='+QUOTEDSTR(ARQUIVO);
qry.Open;
if (qry.RecordCount>0) then
(qry.fieldbyname('BINARIO') as TBlobField).savetofile(Arquivo); //salvando em disco
else
begin
qry.append;
qry.fieldbyname('arquivo').asstring :=arquivo;
(qry.fieldbyname('BINARIO') as TBlobField).loadfromfile(Arquivo); //lendo do disco
qry.post;
end
finally
freeandnil(qry);
end;
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)