ASP.NET 多条件动态参数查询方法

以下便是ASP.NET 多条件动态参数查询的方法,大家可以参考以下代码或直接复制使用哦。 protected void Button1_Click(object sender, EventArgs e) { System.Text.Stri...

以下便是ASP.NET 多条件动态参数查询的方法,大家可以参考以下代码或直接复制使用哦。

   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 条评论

请先 登录 后评论
王凯
王凯

92 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. bngvitmrbj 0 文章