主题:如果要对数据库表中的内容进行有选择的打印怎么设置?哪位兄弟帮帮忙.有点急!
357811852
[专家分:0] 发布于 2007-06-15 00:23:00
[em18]
回复列表 (共2个回复)
沙发
wakswaks [专家分:0] 发布于 2007-06-15 03:22:00
初学
用的什么数据库,控件?
板凳
linjipeng0 [专家分:220] 发布于 2007-09-15 13:34:00
我用的是临时表方法
1:在server中创建一个存储过程
CREATE proc CopyTable
@cnt int,
@custom_type_num varchar(2),
@custom_type_name varchar(10)
As
declare @cnt1 int
if not exists(select * from dbo.sysobjects where id=object_id(N'[dbo].[temp_custom_type]')
and objectproperty(id,N'IsUserTable')=1)
begin
select * into temp_custom_type from custom_type where 0=1
end
select @cnt1=count(*)
from temp_custom_type
where custom_type_num=@custom_type_num
if @cnt>0
begin
if @cnt1<=0
begin
insert into temp_custom_type(custom_type_num,custom_type_name) values(@custom_type_num,@custom_type_name)
end
end
if @cnt=1
begin
select * from temp_custom_type
end
GO
2:再创建一个清空临时表的存储过程
CREATE proc ClearTable
As
if not exists(select * from dbo.sysobjects where id=object_id(N'[dbo].[temp_custom_type]')
and objectproperty(id,N'IsUserTable')=1)
begin
select * into temp_custom_type from custom_type where 0=1
end
delete temp_custom_type
GO
3:在delphi下,一个DBGrid,一个Button,一个ADOStoredProc name为SP1,两个AdoQuery和DataSource
Button的OnCilck事件
var i,cnt:integer;
BookMark : TBookMark;
//iLoop,i: Integer;
//sBH: string;
begin
AdoQuery2.Close;
with sp1 do
begin
close;
ProcedureName:='ClearTable;1';
parameters.Refresh;
ExecProc;
end; // with
BookMark:=AdOQuery1.GetBookmark;
cnt:=DBGrid1.SelectedRows.Count;
for i := 0 to DBGrid1.SelectedRows.Count - 1 do // Iterate
begin
adoQuery1.GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
with sp1 do
begin
close;
ProcedureName:='CopyTable;1';
parameters.Refresh;
parameters.ParamByName('@cnt').Value:=cnt;
parameters.ParamByName('@custom_type_num').Value:=AdOQuery1.fieldByName('custom_type_num').Value;
parameters.ParamByName('@custom_type_name').Value:=AdOQuery1.fieldByName('custom_type_name').Value;
ExecProc;
end; // with
cnt:=cnt-1;
end; // for
AdOQuery1.FreeBookmark(BookMark);
//AdoQuery2.Open;
sp1.Open;
//下面是打印
DBGrid2.DataSource:=DSSP1;
Application.CreateForm(TForm2, Form2);
form2.RMRePort1.LoadFromFile('E:\ljp\多行打印\Untitled.rmf');
form2.RMReport1.ShowReport;
end;
//希望对你有帮助
我来回复