62,046
社区成员
发帖
与我相关
我的任务
分享
select 你那几个列我就不写了
from Student where (StudentID=''or StudentID like '%'+@StudentID+'%')
and ([Name]='' or [Name] like '%'+@[Name]+'%')
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind("");
}
}
protected void bind(string condition)
{
string sql = "select * from table where 1=1 " + condition;
}
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
string condition = "";
if (!string.IsNullOrEmpty(Textid.Text))
{
condition += " and studentid =" + Textid.Text + "%'";//用+=
}
if (!string.IsNullOrEmpty(TextName.Text))
{
condition += " and name like '%" + TextName.Text + "%'";
}
//下面条件省略
}
select 你那几个列我就不写了
from Student where (StudentID=''or StudentID=@StudentID)
and ([Name]='' or [Name]=@[Name])
select 你那几个列我就不写了
from Student where (StudentID=''or StudentID=@StudentID)
and (Name='' or Name=@Name)
以此类推,有几个就用几个作为条件加一个默认条件1=1,之后用键值对吧。 遍历键值对。来控制查询条件。