调用存储过程的复合搜索(分别绑定)和拼接字符串的复合搜索
//(一)调用存储过程的方法
//进行数据检索
protected void btnSearch_Click(object sender, EventArgs e)
{
//由于需求当中要求不可以在后台代码中拼接SQL语句的情况,所以这里采用的方法就是根据选中标签的个数来确定复合搜索存储的个数
EmployeeBll employee = new EmployeeBll();
//第一种情况
if (cbName.Checked && !cbSex.Checked)//名字文本框选中,性别下拉没选中的时候
{
//调用仅使用名字参数的存储过程
//第一种情况
if (cbName.Checked && !cbSex.Checked)//名字文本框选中,性别下拉没选中的时候
{
//调用仅使用名字参数的存储过程
DataTable table = new DataTable();
if (!string.IsNullOrEmpty(txtName.Text))
{
table = employee.getEmployeeDataByName(txtName.Text);
{
table = employee.getEmployeeDataByName(txtName.Text);
//showOrNotBtn(table);
RepeaterEmployee.DataSource = table;
RepeaterEmployee.DataBind();
}
else
{
BindRepeater();
RepeaterEmployee.DataBind();
}
else
{
BindRepeater();
return;
}
}
return;
}
}
//第二种情况
if (cbName.Checked && cbSex.Checked)//名字文本框选中,部门下拉选中
{
//调用使用名字和性别ID的存储过程
if (cbName.Checked && cbSex.Checked)//名字文本框选中,部门下拉选中
{
//调用使用名字和性别ID的存储过程
bindRepeaterByNameAndSexId(txtName.Text, ddlSex.SelectedIndex + 1);
return;
}
return;
}
//第三种情况
if (!cbName.Checked && cbSex.Checked)//名字文本框没选中,部门下拉选中
{
if (!cbName.Checked && cbSex.Checked)//名字文本框没选中,部门下拉选中
{
bindRepeaterBySexId(ddlSex.SelectedIndex + 1);
return;
}
//第四种情况
else//调用没有选中名字文本和部门下拉的存储过程
{
BindRepeater();
}
//第四种情况
else//调用没有选中名字文本和部门下拉的存储过程
{
BindRepeater();
return;
}
}
//拼接字符串的方法
private void btnSearch_Click(object sender, EventArgs e)
{
string s="select id from test where 1=1 ";
txtContent.Text = s;
}
}
//拼接字符串的方法
private void btnSearch_Click(object sender, EventArgs e)
{
string s="select id from test where 1=1 ";
txtContent.Text = s;
if (checkBox1.Checked==true)
{
s+=" and grade=100";
txtContent.Text = s;
}
if (checkBox2.Checked==true)
{
s+=" and grade=200";
txtContent.Text = s;
}
{
s+=" and grade=100";
txtContent.Text = s;
}
if (checkBox2.Checked==true)
{
s+=" and grade=200";
txtContent.Text = s;
}
if (checkBox3.Checked==true)
{
s+=" and grade=300";
txtContent.Text = s;
}
}
{
s+=" and grade=300";
txtContent.Text = s;
}
}