G
gztoms
Unregistered / Unconfirmed
GUEST, unregistred user!
本人想用Delphi+MTS+SQL Server来存储读取任何格式的文件,比如文本格式(DOC,TXT等),
图片格式等等,我认为用流的方法应该可以解决这个问题,曾经试过:
数据库表 :
testtable
id : integer;
content : image;
程序:
procedure TForm1.Button1Click(Sender: TObject);
var
str:Tmemorystream;
sSql : string;
begin
sSql := 'select * from testtable';
ClientDataSet1.Close;
ClientDataSet1.CommandText := sSql;
ClientDataSet1.Open;
str:=Tmemorystream.Create;
Str.LoadFromFile('aa.doc');
str.Position:=0;
ClientDataSet1.insert;
ClientDataSet1['id'] := 1;
Tblobfield(ClientDataSet1.FieldByName('content')).loadfromstream(str);
try
ClientDataSet1.ApplyUpdates(-1);
finally
str.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
str:Tmemorystream;
sSql : string;
begin
sSql := 'select * from testtable';
ClientDataSet1.Close;
ClientDataSet1.CommandText := sSql;
ClientDataSet1.Open;
str:=Tmemorystream.Create;
str.Position:=0;
Tblobfield(ClientDataSet1.FieldByName('content')).savetostream(str);
str.SaveToFile('bb.doc');
str.Free;
end;
Client端用SocketConnection1+ClientDataSet1;
server端用ADOConnection1 + ADOQuery1 + DataSetProvider1;
以上的控件除了相应的设置以外,其余的属性都用默认值;
我在运行过程中虽然没报错,但是数据总是没有保存到数据库,不知是何原因,
请各位大侠多多指教。最好给出例子,先谢谢了!
图片格式等等,我认为用流的方法应该可以解决这个问题,曾经试过:
数据库表 :
testtable
id : integer;
content : image;
程序:
procedure TForm1.Button1Click(Sender: TObject);
var
str:Tmemorystream;
sSql : string;
begin
sSql := 'select * from testtable';
ClientDataSet1.Close;
ClientDataSet1.CommandText := sSql;
ClientDataSet1.Open;
str:=Tmemorystream.Create;
Str.LoadFromFile('aa.doc');
str.Position:=0;
ClientDataSet1.insert;
ClientDataSet1['id'] := 1;
Tblobfield(ClientDataSet1.FieldByName('content')).loadfromstream(str);
try
ClientDataSet1.ApplyUpdates(-1);
finally
str.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
str:Tmemorystream;
sSql : string;
begin
sSql := 'select * from testtable';
ClientDataSet1.Close;
ClientDataSet1.CommandText := sSql;
ClientDataSet1.Open;
str:=Tmemorystream.Create;
str.Position:=0;
Tblobfield(ClientDataSet1.FieldByName('content')).savetostream(str);
str.SaveToFile('bb.doc');
str.Free;
end;
Client端用SocketConnection1+ClientDataSet1;
server端用ADOConnection1 + ADOQuery1 + DataSetProvider1;
以上的控件除了相应的设置以外,其余的属性都用默认值;
我在运行过程中虽然没报错,但是数据总是没有保存到数据库,不知是何原因,
请各位大侠多多指教。最好给出例子,先谢谢了!