• 复合查询


            /// <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);

            }

    感谢来访,共同学习!
  • 相关阅读:
    git---如何解决The authenticity of host can't be established.
    前端模板引擎artTemplate.js
    微信小程序
    小程序的项目结构设计
    拖拽插件SortableJS
    iscroll.js的简单使用方法
    头疼的闭包
    关于setTimeout的妙用前端函数节流
    webpack 加载动态图片
    在React中实现条件渲染的7种方法
  • 原文地址:https://www.cnblogs.com/dingxiaowei/p/3058760.html
Copyright © 2020-2023  润新知