调用存储过程的复合搜索(分别绑定)和拼接字符串的复合搜索

 

 

调用存储过程的复合搜索(分别绑定)和拼接字符串的复合搜索


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

//拼接字符串的方法

   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;
            }
            if (checkBox3.Checked==true)
            {
                s+=" and grade=300";
                txtContent.Text = s;
            }
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值