日期:2014-05-18 浏览次数:20687 次
create Table Users
(
id int,
name nvarchar(20),
age int
)
create proc sp_SGetUserInfo
(
@Name nvarchar(20),
@Age int
)
as
select
*
from
Users
where
(@Name='' or name=@Name) --参数为空 就不执行了
and
(@Age='' or age=@Age)
------解决方案--------------------
简单的写一下,你照着这个来就可以了,不过用了if
string str1=this.TextBox1.text.Trim().ToString();
string str2=this.TextBox2.text.Trim().ToString();
string str3=this.TextBox3.text.Trim().ToString();
//假设处理页为search.aspx
//你在按钮上的处理页写成:"search.aspx?str1="+str1+"&str2="+str2+"&str3="+str3
//下面是search.aspx页的部分代码
string s1,s2,s3;
string str1,str2,str3;
str1=Request.QueryString["str1"].ToString();
str2=Request.QueryString["str2"].ToString();
str3=Request.QueryString["str3"].ToString();
if(str1=="" || str1==null)
{
s1="";
}
else
{
s1=" and 字段名 like '"+str1+"'";
}
if(str2=="" || str2==null)
{
s2="";
}
else
{
s2=" and 字段名 like '"+str2+"'";
}
if(str3=="" || str3==null)
{
s3="";
}
else
{
s3=" and 字段名 like '"+str3+"'";
}
//然后把它们组合起来
string sql="select * from tablename where id<>0";
sql+=s1+s2+s3;