create table ywy_test(
test_no varchar2(20) not null,
test_word blob null);
刚才搜索了一下,发现相关的帖子很多,但好象不是很详细,希望哪位大虾能给出具体的代码。谢谢大家!
13 个解决方案
#1
使用TMemoryStream读入此文件,Copy到TBlobField里面就可以了。
#2
关注
#3
希望mshawk(憨憨)能给出具体的代码。
#4
TBlobField(table1.FieldbyName('test_word')).LoadFromfile(wordfilename)
#5
回复人: wwwwwwww(我我) (2002-1-28 9:46:44) 得0分
保存word文档:
procedure Tfrmdyqk1.BitBtn3Click(Sender: TObject);
var ms:TMemoryStream;
begin
ms:= TMemoryStream.create;
OleContainer1.SaveToStream (ms);
ms.Position := 0;
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open;
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
Query1.fieldbyname('wjdid').value:=7;
Query1.fieldbyname('kzm').value:='txt';
TBlobField(Query1.fieldbyname('qw')).loadfromstream(ms);
ms.free;
Query1.post;
//Query1.applyupdates;
Query1.close;
end;
取出word文档:
procedure Tfrmdyqk1.Button2Click(Sender: TObject);
var strstream:Tmemorystream;
//ls_qw:string;
begin
OleContainer1.DestroyObject;
strstream := Tmemorystream.Create;
query1.Close;
query1.sql.clear;
query1.SQL.Add('select qw from oadbo.bw_qwb where wjid =' + inttostr(77777777));
query1.open ;
query1.First;
Tblobfield(query1.fieldbyname('qw')).savetostream(strstream);
strstream.position:=0;
OleContainer1.loadfromstream(strstream);
strstream.free;
end;
保存word文档:
procedure Tfrmdyqk1.BitBtn3Click(Sender: TObject);
var ms:TMemoryStream;
begin
ms:= TMemoryStream.create;
OleContainer1.SaveToStream (ms);
ms.Position := 0;
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open;
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
Query1.fieldbyname('wjdid').value:=7;
Query1.fieldbyname('kzm').value:='txt';
TBlobField(Query1.fieldbyname('qw')).loadfromstream(ms);
ms.free;
Query1.post;
//Query1.applyupdates;
Query1.close;
end;
取出word文档:
procedure Tfrmdyqk1.Button2Click(Sender: TObject);
var strstream:Tmemorystream;
//ls_qw:string;
begin
OleContainer1.DestroyObject;
strstream := Tmemorystream.Create;
query1.Close;
query1.sql.clear;
query1.SQL.Add('select qw from oadbo.bw_qwb where wjid =' + inttostr(77777777));
query1.open ;
query1.First;
Tblobfield(query1.fieldbyname('qw')).savetostream(strstream);
strstream.position:=0;
OleContainer1.loadfromstream(strstream);
strstream.free;
end;
#6
to hegum(大概):我的Oracle表的数据类型设计为Blob,在以下语句会出错:
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这一步是报错:invaid field type
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
....
还望不吝赐教
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这一步是报错:invaid field type
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
....
还望不吝赐教
#7
to hegum(大概):
我照你写的去做,在执行到第十行时就报错了:
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
...
字段的数据类型为Blob。
我照你写的去做,在执行到第十行时就报错了:
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
...
字段的数据类型为Blob。
#8
当然啊
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
*********这些是别人的程序啊
你要改成自己的啊。
http://202.96.70.228/cakk/delphi/delphi.htm
Delphi 5.X ADO_MTS_COM+高级程序设计篇 Delphi5开发人员指南 85,353k 配书源码 太大了!
delphi5企业级解决方案及应用剖析 13,278k
delphi5编程实例与技巧 12,201k
delphi5数据开发技术
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
*********这些是别人的程序啊
你要改成自己的啊。
http://202.96.70.228/cakk/delphi/delphi.htm
Delphi 5.X ADO_MTS_COM+高级程序设计篇 Delphi5开发人员指南 85,353k 配书源码 太大了!
delphi5企业级解决方案及应用剖析 13,278k
delphi5编程实例与技巧 12,201k
delphi5数据开发技术
#9
procedure TsampleForm.OpenDOCClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
OpenDialog1.Filter:='WORD文档(*.DOC)|*.DOC';{从对话窗选择文件}
if OpenDialog1.Execute then
begin
MyFile:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open;
Edit;
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField,
bmWrite);{‘Doc’为BLOB字段名}
MemSize := MyFile.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Seek(0, soFromBeginning); {Seek 0 bytes from the stream's
end point}
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
try
Post;
except
on E: EDatabaseError do
if HandelException(E)< >0 then
exit
else
raise;
end;
end;
Doc_ole.CreateObjectFromFile(OpenDialog1.FileName,False);
Doc_ole.Run;{Doc_ole为ToleContainer构件名}
end;
end;
---- 以上为向数据库中写入的程序,应用中从对话窗取出文件在ToleContainer构件中显示的同时存入数据库。
procedure TsampleForm.GetDocClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
MyFile:=TFileStream.Create('c:\temp.tmp',fmCreate);
with Query1 do
begin
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField, bmRead);
MemSize := Stream.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Read(Buffer^,MemSize);
MyFile.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
end;
if FileExists('c:\temp.DOC') then
DeleteFile('c:\temp.DOC');
if FileExists('c:\temp.tmp') then
begin
RenameFile('c:\temp.tmp', 'c:\temp.DOC');
Doc_ole.CreateObjectFromFile('c:\temp.DOC',False);
Doc_ole.Run;
end;
end;
---- 以上程序为从数据库从将WORD文档取出,并放在temp.doc的临时文件上并在ToleContainer构件中显示。
---- 在程序的其他部份应准确控制表记录指针,使WORD文档的存取发生在正确的记录位置。
-----------------------------------------
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
OpenDialog1.Filter:='WORD文档(*.DOC)|*.DOC';{从对话窗选择文件}
if OpenDialog1.Execute then
begin
MyFile:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open;
Edit;
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField,
bmWrite);{‘Doc’为BLOB字段名}
MemSize := MyFile.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Seek(0, soFromBeginning); {Seek 0 bytes from the stream's
end point}
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
try
Post;
except
on E: EDatabaseError do
if HandelException(E)< >0 then
exit
else
raise;
end;
end;
Doc_ole.CreateObjectFromFile(OpenDialog1.FileName,False);
Doc_ole.Run;{Doc_ole为ToleContainer构件名}
end;
end;
---- 以上为向数据库中写入的程序,应用中从对话窗取出文件在ToleContainer构件中显示的同时存入数据库。
procedure TsampleForm.GetDocClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
MyFile:=TFileStream.Create('c:\temp.tmp',fmCreate);
with Query1 do
begin
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField, bmRead);
MemSize := Stream.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Read(Buffer^,MemSize);
MyFile.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
end;
if FileExists('c:\temp.DOC') then
DeleteFile('c:\temp.DOC');
if FileExists('c:\temp.tmp') then
begin
RenameFile('c:\temp.tmp', 'c:\temp.DOC');
Doc_ole.CreateObjectFromFile('c:\temp.DOC',False);
Doc_ole.Run;
end;
end;
---- 以上程序为从数据库从将WORD文档取出,并放在temp.doc的临时文件上并在ToleContainer构件中显示。
---- 在程序的其他部份应准确控制表记录指针,使WORD文档的存取发生在正确的记录位置。
-----------------------------------------
#10
这些都要改,你自己改了:)
#11
TO hegum(大概) :
问题的关键在于以下一段话:
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open; //如果Table1含BLOB字段,则在OPEN时就报“Invaid Field Type”错误了。
Edit;
....
sorry,这个问题我在上一个帖子里没写清楚。
问题的关键在于以下一段话:
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open; //如果Table1含BLOB字段,则在OPEN时就报“Invaid Field Type”错误了。
Edit;
....
sorry,这个问题我在上一个帖子里没写清楚。
#12
呵呵,我把字段的数据类型改为LONG RAW就可以了。谢谢大家。
#13
是否是oracle 有问题?我也发现delphi 查询 oracle's blob字段时
显示 ORA-00932: 数据类型不一致(oracle 报错);如果是 sql server 则正常
显示 ORA-00932: 数据类型不一致(oracle 报错);如果是 sql server 则正常
#1
使用TMemoryStream读入此文件,Copy到TBlobField里面就可以了。
#2
关注
#3
希望mshawk(憨憨)能给出具体的代码。
#4
TBlobField(table1.FieldbyName('test_word')).LoadFromfile(wordfilename)
#5
回复人: wwwwwwww(我我) (2002-1-28 9:46:44) 得0分
保存word文档:
procedure Tfrmdyqk1.BitBtn3Click(Sender: TObject);
var ms:TMemoryStream;
begin
ms:= TMemoryStream.create;
OleContainer1.SaveToStream (ms);
ms.Position := 0;
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open;
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
Query1.fieldbyname('wjdid').value:=7;
Query1.fieldbyname('kzm').value:='txt';
TBlobField(Query1.fieldbyname('qw')).loadfromstream(ms);
ms.free;
Query1.post;
//Query1.applyupdates;
Query1.close;
end;
取出word文档:
procedure Tfrmdyqk1.Button2Click(Sender: TObject);
var strstream:Tmemorystream;
//ls_qw:string;
begin
OleContainer1.DestroyObject;
strstream := Tmemorystream.Create;
query1.Close;
query1.sql.clear;
query1.SQL.Add('select qw from oadbo.bw_qwb where wjid =' + inttostr(77777777));
query1.open ;
query1.First;
Tblobfield(query1.fieldbyname('qw')).savetostream(strstream);
strstream.position:=0;
OleContainer1.loadfromstream(strstream);
strstream.free;
end;
保存word文档:
procedure Tfrmdyqk1.BitBtn3Click(Sender: TObject);
var ms:TMemoryStream;
begin
ms:= TMemoryStream.create;
OleContainer1.SaveToStream (ms);
ms.Position := 0;
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open;
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
Query1.fieldbyname('wjdid').value:=7;
Query1.fieldbyname('kzm').value:='txt';
TBlobField(Query1.fieldbyname('qw')).loadfromstream(ms);
ms.free;
Query1.post;
//Query1.applyupdates;
Query1.close;
end;
取出word文档:
procedure Tfrmdyqk1.Button2Click(Sender: TObject);
var strstream:Tmemorystream;
//ls_qw:string;
begin
OleContainer1.DestroyObject;
strstream := Tmemorystream.Create;
query1.Close;
query1.sql.clear;
query1.SQL.Add('select qw from oadbo.bw_qwb where wjid =' + inttostr(77777777));
query1.open ;
query1.First;
Tblobfield(query1.fieldbyname('qw')).savetostream(strstream);
strstream.position:=0;
OleContainer1.loadfromstream(strstream);
strstream.free;
end;
#6
to hegum(大概):我的Oracle表的数据类型设计为Blob,在以下语句会出错:
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这一步是报错:invaid field type
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
....
还望不吝赐教
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这一步是报错:invaid field type
Query1.append;
Query1.fieldbyname('wjid').value:=77777777 ;
....
还望不吝赐教
#7
to hegum(大概):
我照你写的去做,在执行到第十行时就报错了:
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
...
字段的数据类型为Blob。
我照你写的去做,在执行到第十行时就报错了:
Query1.close;
Query1.sql.clear;
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
...
字段的数据类型为Blob。
#8
当然啊
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
*********这些是别人的程序啊
你要改成自己的啊。
http://202.96.70.228/cakk/delphi/delphi.htm
Delphi 5.X ADO_MTS_COM+高级程序设计篇 Delphi5开发人员指南 85,353k 配书源码 太大了!
delphi5企业级解决方案及应用剖析 13,278k
delphi5编程实例与技巧 12,201k
delphi5数据开发技术
Query1.sql.text:='select * from oadbo.bw_qwb';
Query1.open; //在这里报错:Invaid field type
*********这些是别人的程序啊
你要改成自己的啊。
http://202.96.70.228/cakk/delphi/delphi.htm
Delphi 5.X ADO_MTS_COM+高级程序设计篇 Delphi5开发人员指南 85,353k 配书源码 太大了!
delphi5企业级解决方案及应用剖析 13,278k
delphi5编程实例与技巧 12,201k
delphi5数据开发技术
#9
procedure TsampleForm.OpenDOCClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
OpenDialog1.Filter:='WORD文档(*.DOC)|*.DOC';{从对话窗选择文件}
if OpenDialog1.Execute then
begin
MyFile:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open;
Edit;
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField,
bmWrite);{‘Doc’为BLOB字段名}
MemSize := MyFile.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Seek(0, soFromBeginning); {Seek 0 bytes from the stream's
end point}
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
try
Post;
except
on E: EDatabaseError do
if HandelException(E)< >0 then
exit
else
raise;
end;
end;
Doc_ole.CreateObjectFromFile(OpenDialog1.FileName,False);
Doc_ole.Run;{Doc_ole为ToleContainer构件名}
end;
end;
---- 以上为向数据库中写入的程序,应用中从对话窗取出文件在ToleContainer构件中显示的同时存入数据库。
procedure TsampleForm.GetDocClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
MyFile:=TFileStream.Create('c:\temp.tmp',fmCreate);
with Query1 do
begin
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField, bmRead);
MemSize := Stream.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Read(Buffer^,MemSize);
MyFile.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
end;
if FileExists('c:\temp.DOC') then
DeleteFile('c:\temp.DOC');
if FileExists('c:\temp.tmp') then
begin
RenameFile('c:\temp.tmp', 'c:\temp.DOC');
Doc_ole.CreateObjectFromFile('c:\temp.DOC',False);
Doc_ole.Run;
end;
end;
---- 以上程序为从数据库从将WORD文档取出,并放在temp.doc的临时文件上并在ToleContainer构件中显示。
---- 在程序的其他部份应准确控制表记录指针,使WORD文档的存取发生在正确的记录位置。
-----------------------------------------
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
OpenDialog1.Filter:='WORD文档(*.DOC)|*.DOC';{从对话窗选择文件}
if OpenDialog1.Execute then
begin
MyFile:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open;
Edit;
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField,
bmWrite);{‘Doc’为BLOB字段名}
MemSize := MyFile.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Seek(0, soFromBeginning); {Seek 0 bytes from the stream's
end point}
MyFile.Read(Buffer^,MemSize);
Stream.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
try
Post;
except
on E: EDatabaseError do
if HandelException(E)< >0 then
exit
else
raise;
end;
end;
Doc_ole.CreateObjectFromFile(OpenDialog1.FileName,False);
Doc_ole.Run;{Doc_ole为ToleContainer构件名}
end;
end;
---- 以上为向数据库中写入的程序,应用中从对话窗取出文件在ToleContainer构件中显示的同时存入数据库。
procedure TsampleForm.GetDocClick(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
MyFile: TFileStream;
Stream: TBlobStream;
begin
MyFile:=TFileStream.Create('c:\temp.tmp',fmCreate);
with Query1 do
begin
Stream := TBlobStream.Create(FieldByName('Doc') as TBlobField, bmRead);
MemSize := Stream.Size;
Inc(MemSize); {Make room for the buffer's null terminator.}
Buffer := AllocMem(MemSize); {Allocate the memory.}
try
Stream.Read(Buffer^,MemSize);
MyFile.Write(Buffer^,MemSize);
finally
MyFile.Free;
Stream.Free;
end;
end;
if FileExists('c:\temp.DOC') then
DeleteFile('c:\temp.DOC');
if FileExists('c:\temp.tmp') then
begin
RenameFile('c:\temp.tmp', 'c:\temp.DOC');
Doc_ole.CreateObjectFromFile('c:\temp.DOC',False);
Doc_ole.Run;
end;
end;
---- 以上程序为从数据库从将WORD文档取出,并放在temp.doc的临时文件上并在ToleContainer构件中显示。
---- 在程序的其他部份应准确控制表记录指针,使WORD文档的存取发生在正确的记录位置。
-----------------------------------------
#10
这些都要改,你自己改了:)
#11
TO hegum(大概) :
问题的关键在于以下一段话:
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open; //如果Table1含BLOB字段,则在OPEN时就报“Invaid Field Type”错误了。
Edit;
....
sorry,这个问题我在上一个帖子里没写清楚。
问题的关键在于以下一段话:
with table1 do {‘table1’为含BLOB字段的表名}
begin
Open; //如果Table1含BLOB字段,则在OPEN时就报“Invaid Field Type”错误了。
Edit;
....
sorry,这个问题我在上一个帖子里没写清楚。
#12
呵呵,我把字段的数据类型改为LONG RAW就可以了。谢谢大家。
#13
是否是oracle 有问题?我也发现delphi 查询 oracle's blob字段时
显示 ORA-00932: 数据类型不一致(oracle 报错);如果是 sql server 则正常
显示 ORA-00932: 数据类型不一致(oracle 报错);如果是 sql server 则正常