如何将在delphi中将一个word文件或图片写入ms_sql sever数据库

kele2030 2004-05-10 08:55:43
各位前辈:


帮帮忙!

如何将在delphi中将一个word文件或图片写入ms_sql sever数据库

我做的是一个办公系统,这个部分是文件的附件,附件可以是word文档,也
可以是图片,图片还容易一点了,那个word文档怎么办呀。
这个过程类似于E-mail的附件了,首先应选中文件,比如说在d;/soft的一个
word文档,怎么把它存进sql sever的数据库中呀。
数据库连接,是ADO完成的,要是用流来做,还需要两个吗。一个tadoblobstream
,一个tfilesteam,应该怎么做呀
我是真的想不出来了
求求大家,帮帮忙吧。谢谢!!
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kele2030 2004-05-11
  • 打赏
  • 举报
回复
我代表菜鸟一族,对各位大虾致以最崇高的敬意!!


谢谢!
boytomato 2004-05-10
  • 打赏
  • 举报
回复
// 个通过 , 'doc' 的数据库中为image 类型
// 不管是WORD,EXCLE,还中JPG的都能用
// 注意打开文件时一定要先定位(即要先写sql 查询确定有个再打开 ),要不然会出错,还有就是临时文件的删除。。
// delphi 7+sql2000通过。。



unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, shellapi,Buttons, OleCtnrs;


type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
ADOQuery1: TADOQuery;
OleContainer1: TOleContainer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
s:string;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
if not ADOQuery1.Active then ADOQuery1.Open;
ADOQuery1.Append;
s :=ExtractFileName(OpenDialog1.FileName);
(ADOQuery1.FieldByName('doc') as TBlobField).LoadFromFile(OpenDialog1.filename);
ADOQuery1.Post;

end;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
(ADOQuery1.FieldByName('doc') as TBlobField).savetoFile(ExtractFileDir(Application.ExeName)+'\'+s);

olecontainer1.CreateObjectFromFile(ExtractFileDir(Application.ExeName)+'\'+s,false);
olecontainer1.DoVerb(1);

// shellexecute(handle,nil,pchar(s),nil,nil,sw_shownormal);
end;

end.
boytomato 2004-05-10
  • 打赏
  • 举报
回复
// 个通过 , 'doc' 的数据库中为image 类型
// 不管是WORD,EXCLE,还中JPG的都能用
// 注意打开文件时一定要先定位(即要先写sql 查询确定有个再打开 ),要不然会出错,还有就是临时文件的删除。。
// delphi 7+sql2000通过。。



unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, shellapi,Buttons, OleCtnrs;


type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
ADOQuery1: TADOQuery;
OleContainer1: TOleContainer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
s:string;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
if not ADOQuery1.Active then ADOQuery1.Open;
ADOQuery1.Append;
s :=ExtractFileName(OpenDialog1.FileName);
(ADOQuery1.FieldByName('doc') as TBlobField).LoadFromFile(OpenDialog1.filename);
ADOQuery1.Post;

end;
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
(ADOQuery1.FieldByName('doc') as TBlobField).savetoFile(ExtractFileDir(Application.ExeName)+'\'+s);

// (ADOQuery1.FieldByName('doc') as TBlobField).savetoFile('你要的路径' +s) ;


shellexecute(handle,nil,pchar(s),nil,nil,sw_shownormal);
end;

end.

lijinghe1 2004-05-10
  • 打赏
  • 举报
回复
每星期必有人问的问题

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧