可以动态增加、删除查询名和对应的条件(比如说查询条件在一个下拉菜单里、选择一个名,他对应得查询条件也可以跟着选择)如:请选择:(下拉菜单:名称、日期等等)(下拉菜单条件:包含、等于、先于、后于等等)(输入框:条件值)(增加条件按钮)(删除条件按钮)................这里往下增加或者删除以上的下拉菜单等控件

解决方案 »

  1.   

    那你string 拼组SQL,然后把那些传入进来不可以吗?
      

  2.   

    动态添加控件到页面,再遍历页面控件获取相关值
    构建动态SQL语句查询数据
      

  3.   

    一个简单的例子using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            DataGridView DGV = new DataGridView();        public Form1()
            {
                InitializeComponent();            this.Size = new Size(500, 500);            DGV.Parent = this;
                DGV.Dock = DockStyle.Top;
                DGV.AllowUserToAddRows = false;
                DGV.EditMode = DataGridViewEditMode.EditOnEnter;            DataTable DT = new DataTable();            DT.Columns.Add("Field");
                DT.Columns.Add("Caption");
                DT.Rows.Add(new Object[] { "A", "字段A" });
                DT.Rows.Add(new Object[] { "B", "字段B" });
                DT.Rows.Add(new Object[] { "C", "字段C" });            DataGridViewComboBoxColumn CC = new DataGridViewComboBoxColumn();            CC.HeaderText = "字段";
                CC.DataSource = DT;
                CC.ValueMember = "Field";
                CC.DisplayMember = "Caption";
                CC.DataPropertyName = "Field";
                DGV.Columns.Add(CC);            DT = new DataTable();            DT.Columns.Add("Operation");
                DT.Rows.Add(new Object[] { ">" });
                DT.Rows.Add(new Object[] { ">=" });
                DT.Rows.Add(new Object[] { "=" });
                DT.Rows.Add(new Object[] { "<" });
                DT.Rows.Add(new Object[] { "<=" });
                DT.Rows.Add(new Object[] { "like" });            CC = new DataGridViewComboBoxColumn();
                CC.DataSource = DT;
                CC.ValueMember = "Operation";
                CC.DataPropertyName = "Operation";
                DGV.Columns.Add(CC);            DGV.Columns.Add("Value", "值");            DGV.Rows.Add(3);            Button B = new Button();
                B = new Button();
                B.Parent = this;
                B.Location = new Point(0, 200);
                B.Click += new EventHandler(B_Click);
            }        void B_Click(object sender, EventArgs e)
            {
                String S = "SELECT * FROM TABLE WHERE (1==1) ";            foreach (DataGridViewRow DR in DGV.Rows)
                    if (!String.IsNullOrEmpty((String)DR.Cells[0].Value))
                        S += " AND (" + DR.Cells[0].Value + DR.Cells[1].Value + DR.Cells[2].Value + ")";            MessageBox.Show(S);
            }
        }
    }
      

  4.   

    楼上说的似乎还不够理想,比如我三个字段都选择B,而不选择Operator,也不填入值,那生成的语句就是
    Select * from Table Where (1==1) and (B) and (B) and (B)
      

  5.   

    追问,winform中datetimepicker 如何把它显示的设置成空啊