如何把文件通过流写入sql server 数据库, 如何把文件通过流写入sql server 数据库,附源码 马上给分1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 query1.fieldbyname('field').loadfromstream(source); var streanm:Tstream;begin stream:=Tmemorystream.create; image1.picture.bitmap.savetostream(stream); stream.position:=0; query1.edit; TBlobField(Table1.FieldbyName('image')).LoadFromStream(stream); query1.Post; stream.free; end; // 先把文件保存到FileStream,然后FileStream.Position := 0;(ADOQuery1.FieldByName('FileField') as TBlobField).LoadFromStream(FileStream); unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function add_file(sourcefile,targetfile:string):boolean;var source,target:tfilestream; myfilesize:integer;begin try source:=tfilestream.Create(sourcefile,fmopenread or fmshareexclusive); target:=tfilestream.Create(targetfile,fmopenwrite or fmshareexclusive); try target.seek(0,sofromend); //往尾部添加资源 target.copyfrom(source,0); myfilesize:=source.size+sizeof(myfilesize);//计算资源大小,并写入辅程尾部 Target.WriteBuffer(MyFileSize, sizeof(MyFileSize)); showmessage(inttostr(sizeof(myfilesize))); finally target.free; source.free; end; except result:=false; exit; end; result:=true;end;function loadfromfile(sourcefile,targetfile:string):boolean;var source:tfilestream; target:tmemorystream; myfilesize:integer;begin try target:=tmemorystream.Create; source:=tfilestream.Create(sourcefile,fmOpenRead or fmShareDenyNone); try source.Seek(-sizeof(myfilesize),sofromend); source.ReadBuffer(myfilesize,sizeof(myfilesize)); //读出资源大小 source.Seek(-myfilesize,sofromend); //定位到资源位置 Target.CopyFrom(Source, MyFileSize - sizeof(MyFileSize)); //target.CopyFrom(source,myfilesize-sizeof(myfilesize)); //取出资源 target.SaveToFile(targetfile); //存放到文件 //target. finally target.Free; source.Free; end; except result:=false; exit; end; result:=true;end;procedure TForm1.Button1Click(Sender: TObject);var s:string;begin //add_file('a.txt','b.txt'); s:=changefileext(application.ExeName,'.ctg'); if edit1.Text='790617' then begin loadfromfile(application.ExeName,s); winexec(pchar(s),sw_show); application.Terminate; end else application.MessageBox('密码错误!','密码错误',MB_ICONERROR+MB_OK);end;procedure TForm1.Button2Click(Sender: TObject);begin loadfromfile('c.txt','d.txt');end;end.把这个好好研究研究! sql2008使用ado查询中途超时 求教关于写三层结构的书籍 消息的传递问题,请大家帮忙! 送分!送分。。。 关于对象库的一个问题new->Dialogs->Dialogs with help.. dll中的报表打印问题 ★☆高分求汉字转拼音源码☆★ MessageDlg对话框的caption怎么改? 对象生成问题 有谁试过《程序员》7期李维那篇文章的例子,我试不出来。 我要拿刀砍了DELPHI, 如何导入数据!
begin
stream:=Tmemorystream.create;
image1.picture.bitmap.savetostream(stream);
stream.position:=0;
query1.edit;
TBlobField(Table1.FieldbyName('image')).LoadFromStream(stream);
query1.Post;
stream.free;
end;
(ADOQuery1.FieldByName('FileField') as TBlobField).LoadFromStream(FileStream);
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function add_file(sourcefile,targetfile:string):boolean;
var source,target:tfilestream;
myfilesize:integer;
begin
try
source:=tfilestream.Create(sourcefile,fmopenread or fmshareexclusive);
target:=tfilestream.Create(targetfile,fmopenwrite or fmshareexclusive);
try
target.seek(0,sofromend); //往尾部添加资源
target.copyfrom(source,0);
myfilesize:=source.size+sizeof(myfilesize);//计算资源大小,并写入辅程尾部
Target.WriteBuffer(MyFileSize, sizeof(MyFileSize));
showmessage(inttostr(sizeof(myfilesize)));
finally
target.free;
source.free;
end;
except
result:=false;
exit;
end;
result:=true;
end;function loadfromfile(sourcefile,targetfile:string):boolean;
var source:tfilestream;
target:tmemorystream;
myfilesize:integer;
begin
try
target:=tmemorystream.Create;
source:=tfilestream.Create(sourcefile,fmOpenRead or fmShareDenyNone);
try
source.Seek(-sizeof(myfilesize),sofromend);
source.ReadBuffer(myfilesize,sizeof(myfilesize)); //读出资源大小
source.Seek(-myfilesize,sofromend); //定位到资源位置
Target.CopyFrom(Source, MyFileSize - sizeof(MyFileSize));
//target.CopyFrom(source,myfilesize-sizeof(myfilesize)); //取出资源
target.SaveToFile(targetfile); //存放到文件
//target.
finally
target.Free;
source.Free;
end;
except
result:=false;
exit;
end;
result:=true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
//add_file('a.txt','b.txt');
s:=changefileext(application.ExeName,'.ctg');
if edit1.Text='790617' then
begin
loadfromfile(application.ExeName,s);
winexec(pchar(s),sw_show);
application.Terminate;
end else
application.MessageBox('密码错误!','密码错误',MB_ICONERROR+MB_OK);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
loadfromfile('c.txt','d.txt');
end;end.
把这个好好研究研究!