不我不能用Session因为这个定义的对象太多了。容易引起一些错误。 EndTime 也没有对应的关系。现在就是想用一个查询语句。来全部查询,如果为空的话也可以进行查询,众所周知道。如果我对应的控件没有数据的话,那我就无法用Select * from b_new where txtStartTime="" 这样是不可以的吧。。对不?
还有个问题就是如果我在 public static strSelect="select * from b where pp='"+Session["userName"]+"'"; 没法写Seesion["userName"]这个对象,它告诉我Seesion["userName"]不是静态对象无法调用。怎么解决
不管是否为null,都传到存储过程(sp)去,然后加上以下判断即可: select * from talbe1 where ((ID=@id and @id is not null) or (@id is null))
in sql you can use isnull to judge it
在存储过程里面可以如下做:@DepartmentID varchar(12) @PersonID varchar(12) @StartTime datetime @EndTime datetime以上是存储过程的参数 过程中如下处理: declare @whereinfo = varchar(8000)set @whereinof = ' 1=1 ' if(@DepartmentID is not null and @DepartmentID <> '') { set whereinof = whereinof + 'departId = ' + @DepartmentID } .....4个参数都如上处理最后调用exec('select * from ' + @whereinof )说白了,就是动态构造SQL
end if
Page.IsPostBack是指頁面被自己加載的事件。
{
//不空则取值
}//继续下一个控件
if(String.Trim(txtEndTime.Text) != "")
{
//不空则取值
}
......
///这样不行嘛?
http://www.yesky.com/SoftChannel/72342380468043776/20030610/1706647.shtml
public static strSelect="select * from b where pp='"+Session["userName"]+"'";
没法写Seesion["userName"]这个对象,它告诉我Seesion["userName"]不是静态对象无法调用。怎么解决
select *
from talbe1
where ((ID=@id and @id is not null) or (@id is null))
@PersonID varchar(12)
@StartTime datetime
@EndTime datetime以上是存储过程的参数
过程中如下处理:
declare @whereinfo = varchar(8000)set @whereinof = ' 1=1 '
if(@DepartmentID is not null and @DepartmentID <> '')
{
set whereinof = whereinof + 'departId = ' + @DepartmentID
}
.....4个参数都如上处理最后调用exec('select * from ' + @whereinof )说白了,就是动态构造SQL
set whereinof = whereinof + 'departId = ' + @DepartmentID
---> set whereinof = whereinof + 'AND departId = ' + @DepartmentID