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

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;//查询按钮
            if (IsPostBack == false)
            {
                Repeater1.DataSource = new CarData().SelectAll();
                Repeater1.DataBind();
            }
        }
        void Button1_Click(object sender, EventArgs e)
        {
            Hashtable hs = new Hashtable();
            int ccc = 0;
            string Tsql = "select *from car";
            if (TextBox1.Text != "")
            {
                Tsql += " where name like @name ";
                hs.Add("@name", "%" + TextBox1.Text + "%");
                ccc++;
            }
            if (TextBox2.Text != "")//不为空进行拼接
            {
                if (ccc > 0)
                {
                    Tsql += " and powers like @pow";
                }
                else
                {
                    Tsql += " where powers like @pow";
                }
                hs.Add("@pow", "%" + TextBox2.Text + "%");
                ccc++;
            }
            if (TextBox3.Text != "")//第三个框为空
            {
                if (ccc > 0)
                {
                    Tsql += " and price " + DropDownList1.SelectedItem.Value + " @pri";
                }
                else
                {
                    Tsql += " where price " + DropDownList1.SelectedItem.Value + " @pri";
                }
                hs.Add("@pri", TextBox3.Text);
                ccc++;
            }
            Label1.Text = Tsql;
            Repeater1.DataSource = new CarData().Select(Tsql,hs);
            Repeater1.DataBind();
        }
       
    }
  • 相关阅读:
    Java 数组算法列题解析
    Java数组总结
    go实现汉诺塔
    go实现归并排序
    css清除浮动深度解析
    jquery阻止事件冒泡
    java
    getComputedStyle/currentStyle/style之间的爱恨情仇
    js基础总结
    元素堆叠问题、z-index、position
  • 原文地址:https://www.cnblogs.com/suiyuejinghao123/p/5706014.html
Copyright © 2011-2022 走看看