多条件动态参数查询方法

来源:互联网 发布:js触发超链接点击事件 编辑:程序博客网 时间:2024/05/16 05:42
          protected void Button1_Click(object sender, EventArgs e)        {            System.Text.StringBuilder strWhere = new System.Text.StringBuilder();            strWhere.Append(" 1=1 ");//1=1全匹配,相当于没有条件            if (this.TextBox1.Text.Trim() != "")//第一个条件            {                strWhere.AppendFormat(" and Yuan_Name='{0}'", this.TextBox1.Text.Trim());            }            if (this.TextBox2.Text.Trim() != "")//第二个条件            {                strWhere.AppendFormat(" and Department_Name='{0}'", this.TextBox2.Text.Trim());            }            DataSet ds_Yuan = yuan.GetDataSet(strWhere.ToString());            this.GV_Yuan.DataSource = ds_Yuan.Tables["T_Yuan"];            this.GV_Yuan.DataBind();            this.lbl_Count.Text = ds_Yuan.Tables["T_Yuan"].Rows.Count.ToString();            Session["T_Yuan"] = ds_Yuan.Tables["T_Yuan"];        }

0 0
原创粉丝点击