把GridView用SqlDataSource作数据源,点GridView的"删除"时就执行SqlDataSource中DeleteCommand对应的一个存储过程A
现在发现参数设置不太正常... 当存储过程A 当中不需要参数时,即使你不为DeleteCommand提供参数它都会默认把GridView中DataKeyNames指定的字段(假设为字段id)当作参数@id
自动传给存储过程A,结果程序出错,提示"过程 A 没有参数,但却为该过程提供了参数。"所以存储过程A中一定要有GridView的DataKeyNames指定的字段作为参数输入,
假如
存储过程A是CREATE PROCEDURE [dbo].A
@id nvarchar(40),
@D nvarchar(40)
AS
GO那么在指定DeleteCommand的参数时只需要提供@D参数即可,,不能提供@id,提供了@id参数反而会出错,,<asp:SqlDataSource ......>
........
........
<DeleteParameters>
<asp:Parameter DefaultValue="d" Name="D" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>
不知道是否真的只能这样做,,但我实践发现的就是如此...大家有没有更好的方法?
现在发现参数设置不太正常... 当存储过程A 当中不需要参数时,即使你不为DeleteCommand提供参数它都会默认把GridView中DataKeyNames指定的字段(假设为字段id)当作参数@id
自动传给存储过程A,结果程序出错,提示"过程 A 没有参数,但却为该过程提供了参数。"所以存储过程A中一定要有GridView的DataKeyNames指定的字段作为参数输入,
假如
存储过程A是CREATE PROCEDURE [dbo].A
@id nvarchar(40),
@D nvarchar(40)
AS
GO那么在指定DeleteCommand的参数时只需要提供@D参数即可,,不能提供@id,提供了@id参数反而会出错,,<asp:SqlDataSource ......>
........
........
<DeleteParameters>
<asp:Parameter DefaultValue="d" Name="D" Type="String" />
</DeleteParameters>
</asp:SqlDataSource>
不知道是否真的只能这样做,,但我实践发现的就是如此...大家有没有更好的方法?
CREATE procedure select_pagesize(
@select_list varchar(1000)='*',--不需要select
@table_name varchar(100),
@where varchar(1000)='',--不需要where
@primary_key varchar(100),--当是表联合时,加表名前缀.
@order_by varchar(200),--需要完整的子句 order by ...
@page_size smallint=20,--每页记录
@page_index int=1,--页索引
@do_count bit=0,--1只统计总数
@total1 int output)--统计总数
as
/*
过程名:通用存储过程分页
使用示例:
单表sql调用:exec select_pagesize 'login_id,login_name','tb_login',' login_name like ''%%''','login_id',' order by login_dt desc',20,10
多表sql调用:exec select_pagesize 'a.login_id,a.login_name,b.pro_name','tb_login a,tb_code_province b',' a.pro_id=b.pro_id and a.login_name like ''%%''','a.login_id',' order by a.login_dt desc',20,10
备注:外部程序调用不需要转义单引号
原型结构:select top 20 select_list
from tablename
where z_id not in(select z_id from (select top 100 z_id from tablename order by order_by) temptable)
and ...
order by order_by
*/ --声明要用到的变量,@temp1是正常的分页语句字符串,@temp2是最后一页的分页语句字符串,@page_total表一共有几页,@last_page
--是最后一页的页码
declare @temp1 varchar(500),@temp2 nvarchar(500),@page_total int,@last_page int
--构造获得总页的数的检索语句
set @temp2=N'select @total2=count(*) from ' + @table_name + ' where ' + @where
--执行检索语句,取得总的记录条数
exec sp_executesql @temp2,N' @total2 int output ',@total1 output
declare @sql_str varchar(8000)
declare @record_min int
declare @new_where varchar(1000),@newin_where varchar(1000)
if @where=''--重新为梳理,此过程时性能的考虑,因此不使用 where 1=1 再追加条件。
begin
select @new_where=''
select @newin_where=''
end
else
begin
select @new_where=' and '+@where
select @newin_where=' where '+@where
end
-- if @do_count=1
-- select @total1='select count(*) from '+@table_name+@newin_where
---else
if @page_index=1
if @where=''
select @sql_str='select top '+convert(varchar,@page_size)+ ' '+@select_list+' from '+@table_name+' '+@order_by
else
select @sql_str='select top '+convert(varchar,@page_size)+ ' '+@select_list+' from '+@table_name+' where '+@where+' '+@order_by
else
begin
select @record_min=(@page_index-1)*@page_size
select @sql_str='select top '+convert(varchar,@page_size)+' '+@select_list+' from '+@table_name+' where '+@primary_key+' not in (select '+stuff(@primary_key,1,charindex('.',@primary_key),'')
select @sql_str=@sql_str+' from (select top '+convert(varchar,@record_min)+' '+@primary_key+' from '+@table_name+@newin_where+' '+@order_by+') temptable0000)'
select @sql_str=@sql_str+@new_where+' '+@order_by
end
--print @sql_str
exec(@sql_str)
GO