zoukankan      html  css  js  c++  java
  • 复合查询

            /// <summary>
            /// 复合查询
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnCheck_Click(object sender, EventArgs e)
            {
                //方法一
                //StringBuilder sb = new StringBuilder();
                //sb.Append("select * from T_Customers where 1=1\n");
                //if (ckbName.Checked)
                //{
                //    sb.Append("and Name like @name\n");
                //}
                //if (ckbPhone.Checked)
                //{
                //    sb.Append("and Phone like @phone\n");
                //}
                //if (ckbCarNum.Checked)
                //{
                //    sb.Append("and CarNum like @carnum\n");
                //}
                //MessageBox.Show(sb.ToString());

                //方法二
                List<string> listWhere = new List<string>();
                if (ckbName.Checked)
                {
                    listWhere.Add("Name like @name\n");
                }
                if (ckbPhone.Checked)
                {
                    listWhere.Add("Phone like @phone\n");
                }
                if (ckbCarNum.Checked)
                {
                    listWhere.Add("CarNum like @carnum\n");
                }
                string sql = "select * from T_Custumers\n";
                if (listWhere.Count>0)
                {
                    string sqlWhere = string.Join("and ", listWhere.ToArray());
                    sql += " where " + sqlWhere;
                }
                MessageBox.Show(sql);

            }

    感谢来访,共同学习!
  • 相关阅读:
    拓扑排序,bitset~[JSOI2015]最小表示
    字符串算法~KMP
    校内团队训练赛2
    校内团队训练赛
    CodeForces
    莫队算法基础与练习
    lintcode-452-删除链表中的元素
    lintcode-451-两两交换链表中的节点
    lintcode-450-K组翻转链表
    lintcode-445-余弦相似度
  • 原文地址:https://www.cnblogs.com/dingxiaowei/p/3058760.html
Copyright © 2011-2022 走看看