• 复合查询


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

            }

  • 相关阅读:
    解决VS2013中的控制台一闪而过的问题
    无法查找或打开 PDB 文件解决办法
    一些课题
    KVM下raw和qcow2格式磁盘文件IO测试
    CentOS6.5下安装jdk配置环境变量错误问题:
    小代码训练
    tomcat启动一闪而过处理
    Tomcat 中get请求中含有中文字符时乱码的处理
    ssm框架错误展示-1
    a标签指定的url,在表单提交前进行js验证的实现
  • 原文地址:https://www.cnblogs.com/java20130723/p/3211477.html
Copyright © 2020-2023  润新知