Live2D

sql存储过程,根据多个条件查询,返回一个dataTable或者DataSet

不废话,先直接代码

首先sql部分(我在这里加了一个@zx作为判断,一般不需要这个参数):

ALTER Proc [dbo].[Proc_Boss_Show]
@StrIndex varchar(500),--开始条数
@EndIndex varchar(500),--结束条数
@StrWhere  varchar(max),
@zx int --执行区间  1执行 top n  2显示所有数据
as

begin
     declare  @strSqlstr varchar(500)
     
     if(@zx=1)
     begin
         set @strSqlstr='select  * from (select top '+@EndIndex
         set @strSqlstr+='  row_number() over(order by 提货时间 desc)
         as xx,* from View_Boss_Show  where 1=1 '+@StrWhere
         set @strSqlstr+=' ) as xx where xx>'+@StrIndex


    end
     if(@zx=2)
    begin
       set @strSqlstr='select * from  View_Boss_Show  where  1=1 '+@StrWhere
    end

print @strSqlstr
exec(@strSqlstr)

asp.net代码(直接用DataTable接收):

DataTable dt = null;
            try
            {
                dt = DBHelper.GetDataTable("Proc_View_show1391", para);
            }
            catch (Exception ex)
            { //throw new Exception(ex.ToString());
            }

 

posted @ 2017-11-01 17:34  楚景然  阅读(2262)  评论(0编辑  收藏  举报