J
jrx
Unregistered / Unconfirmed
GUEST, unregistred user!
在Sql server数据库建表
Create Table Report
(Report_id VarChar(10),
ReportFile Image
)
使用ClientDataSet保存Excel文件到Report表:
1、用ClientDataSet直接提交
var
tms: TMemoryStream;
begin
ClientDataSet.Close;
ClientDataSet.CommandText := 'Select * from Repart where Repost_ID = 1';
ClientDataSet.Open;
if OpenDialog.Execute then
begin
tms := TMemoryStream.Create;
tms.LoadFromFile(OpenDialog.FileName);
tms.Position := 0;
try
ClientDataSet.Edit;
TBlobField(ClientDataSet.FieldByName('ReportFile')).LoadFromStream(tms);
ClientDataSet.Post;
ClientDataSet.ApplyUpdates(0);
finally
tms.Free;
end;
end;
end;
这种方法有时候不能提交数据,ClientDataSet也不抱错。
2、在直接用AdoQuery执行Sql语句
var
tms: TMemoryStream;
begin
if OpenDialog.Execute then
begin
tms := TMemoryStream.Create;
tms.LoadFromFile(OpenDialog.FileName);
tms.Position := 0;
try
AdoQuery.Close;
AdoQuery.SQL.Clear;
AdoQuery.SQL.Add('update Report Set ReportFile =: ReportFile where Report_ID = 1');
AdoQuery.Parameters[0].LoadFromStream(tms, ftblob);
Adoquery.ExecSQL;
finally
tms.Free;
end;
end;
这种方法百发百中。
3、用CLientDataSet执行Sql 语句
var
tms: TMemoryStream;
begin
if OpenDialog.Execute then
begin
tms := TMemoryStream.Create;
tms.LoadFromFile(OpenDialog.FileName);
tms.Position := 0;
try
CLientDataSet.Close;
CLientDataSet.SQL.Clear;
CLientDataSet.SQL.Add('update Report Set ReportFile =: ReportFile where Report_ID = 1');
CLientDataSet.Params.ParamByName.LoadFromStream(tms, ftblob);
CLientDataSet.ExecSQL;
finally
tms.Free;
end;
end;
执行到CLientDataSet.ExecSQL抱错:操作数类型冲突:text与Image不兼容。
到底该怎样把Excel文件保存到数据库中。
Create Table Report
(Report_id VarChar(10),
ReportFile Image
)
使用ClientDataSet保存Excel文件到Report表:
1、用ClientDataSet直接提交
var
tms: TMemoryStream;
begin
ClientDataSet.Close;
ClientDataSet.CommandText := 'Select * from Repart where Repost_ID = 1';
ClientDataSet.Open;
if OpenDialog.Execute then
begin
tms := TMemoryStream.Create;
tms.LoadFromFile(OpenDialog.FileName);
tms.Position := 0;
try
ClientDataSet.Edit;
TBlobField(ClientDataSet.FieldByName('ReportFile')).LoadFromStream(tms);
ClientDataSet.Post;
ClientDataSet.ApplyUpdates(0);
finally
tms.Free;
end;
end;
end;
这种方法有时候不能提交数据,ClientDataSet也不抱错。
2、在直接用AdoQuery执行Sql语句
var
tms: TMemoryStream;
begin
if OpenDialog.Execute then
begin
tms := TMemoryStream.Create;
tms.LoadFromFile(OpenDialog.FileName);
tms.Position := 0;
try
AdoQuery.Close;
AdoQuery.SQL.Clear;
AdoQuery.SQL.Add('update Report Set ReportFile =: ReportFile where Report_ID = 1');
AdoQuery.Parameters[0].LoadFromStream(tms, ftblob);
Adoquery.ExecSQL;
finally
tms.Free;
end;
end;
这种方法百发百中。
3、用CLientDataSet执行Sql 语句
var
tms: TMemoryStream;
begin
if OpenDialog.Execute then
begin
tms := TMemoryStream.Create;
tms.LoadFromFile(OpenDialog.FileName);
tms.Position := 0;
try
CLientDataSet.Close;
CLientDataSet.SQL.Clear;
CLientDataSet.SQL.Add('update Report Set ReportFile =: ReportFile where Report_ID = 1');
CLientDataSet.Params.ParamByName.LoadFromStream(tms, ftblob);
CLientDataSet.ExecSQL;
finally
tms.Free;
end;
end;
执行到CLientDataSet.ExecSQL抱错:操作数类型冲突:text与Image不兼容。
到底该怎样把Excel文件保存到数据库中。