情况是这样的,我使用了两个combobox和两个checkedlistbox控件,分别都有一个checkbox加以控制。
小弟我的sql不好,请问应该怎么样写C#+Sql的语句才能实现以上次个控件的组合查询?

解决方案 »

  1.   

    代码是这样的:
    //form1.designer.cs
    namespace WindowsApplication2
    {
        partial class Form1
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows 窗体设计器生成的代码        /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.groupBox1 = new System.Windows.Forms.GroupBox();
                this.button1 = new System.Windows.Forms.Button();
                this.checkedListBox2 = new System.Windows.Forms.CheckedListBox();
                this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
                this.comboBox2 = new System.Windows.Forms.ComboBox();
                this.comboBox1 = new System.Windows.Forms.ComboBox();
                this.checkBox4 = new System.Windows.Forms.CheckBox();
                this.checkBox3 = new System.Windows.Forms.CheckBox();
                this.checkBox2 = new System.Windows.Forms.CheckBox();
                this.checkBox1 = new System.Windows.Forms.CheckBox();
                this.groupBox1.SuspendLayout();
                this.SuspendLayout();
                // 
                // groupBox1
                // 
                this.groupBox1.Controls.Add(this.button1);
                this.groupBox1.Controls.Add(this.checkedListBox2);
                this.groupBox1.Controls.Add(this.checkedListBox1);
                this.groupBox1.Controls.Add(this.comboBox2);
                this.groupBox1.Controls.Add(this.comboBox1);
                this.groupBox1.Controls.Add(this.checkBox4);
                this.groupBox1.Controls.Add(this.checkBox3);
                this.groupBox1.Controls.Add(this.checkBox2);
                this.groupBox1.Controls.Add(this.checkBox1);
                this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.groupBox1.Location = new System.Drawing.Point(0, 0);
                this.groupBox1.Name = "groupBox1";
                this.groupBox1.Size = new System.Drawing.Size(299, 450);
                this.groupBox1.TabIndex = 0;
                this.groupBox1.TabStop = false;
                this.groupBox1.Text = "查询";
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(160, 415);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 8;
                this.button1.Text = "查询";
                this.button1.UseVisualStyleBackColor = true;
                // 
                // checkedListBox2
                // 
                this.checkedListBox2.FormattingEnabled = true;
                this.checkedListBox2.Items.AddRange(new object[] {
                "1",
                "2",
                "3",
                "4",
                "5"});
                this.checkedListBox2.Location = new System.Drawing.Point(116, 294);
                this.checkedListBox2.Name = "checkedListBox2";
                this.checkedListBox2.Size = new System.Drawing.Size(120, 84);
                this.checkedListBox2.TabIndex = 7;
                // 
                // checkedListBox1
                // 
                this.checkedListBox1.FormattingEnabled = true;
                this.checkedListBox1.Items.AddRange(new object[] {
                "1",
                "2",
                "3",
                "4",
                "5"});
                this.checkedListBox1.Location = new System.Drawing.Point(115, 172);
                this.checkedListBox1.Name = "checkedListBox1";
                this.checkedListBox1.Size = new System.Drawing.Size(120, 84);
                this.checkedListBox1.TabIndex = 6;
                // 
                // comboBox2
                // 
                this.comboBox2.FormattingEnabled = true;
                this.comboBox2.Items.AddRange(new object[] {
                "1",
                "2"});
                this.comboBox2.Location = new System.Drawing.Point(115, 94);
                this.comboBox2.Name = "comboBox2";
                this.comboBox2.Size = new System.Drawing.Size(121, 20);
                this.comboBox2.TabIndex = 5;
                // 
                // comboBox1
                // 
                this.comboBox1.FormattingEnabled = true;
                this.comboBox1.Items.AddRange(new object[] {
                "1",
                "2"});
                this.comboBox1.Location = new System.Drawing.Point(115, 38);
                this.comboBox1.Name = "comboBox1";
                this.comboBox1.Size = new System.Drawing.Size(121, 20);
                this.comboBox1.TabIndex = 4;
                // 
                // checkBox4
                // 
                this.checkBox4.AutoSize = true;
                this.checkBox4.Location = new System.Drawing.Point(31, 294);
                this.checkBox4.Name = "checkBox4";
                this.checkBox4.Size = new System.Drawing.Size(78, 16);
                this.checkBox4.TabIndex = 3;
                this.checkBox4.Text = "checkBox4";
                this.checkBox4.UseVisualStyleBackColor = true;
                // 
                // checkBox3
                // 
                this.checkBox3.AutoSize = true;
                this.checkBox3.Location = new System.Drawing.Point(31, 172);
                this.checkBox3.Name = "checkBox3";
                this.checkBox3.Size = new System.Drawing.Size(78, 16);
                this.checkBox3.TabIndex = 2;
                this.checkBox3.Text = "checkBox3";
                this.checkBox3.UseVisualStyleBackColor = true;
                // 
                // checkBox2
                // 
                this.checkBox2.AutoSize = true;
                this.checkBox2.Location = new System.Drawing.Point(31, 96);
                this.checkBox2.Name = "checkBox2";
                this.checkBox2.Size = new System.Drawing.Size(78, 16);
                this.checkBox2.TabIndex = 1;
                this.checkBox2.Text = "checkBox2";
                this.checkBox2.UseVisualStyleBackColor = true;
                // 
                // checkBox1
                // 
                this.checkBox1.AutoSize = true;
                this.checkBox1.Location = new System.Drawing.Point(31, 42);
                this.checkBox1.Name = "checkBox1";
                this.checkBox1.Size = new System.Drawing.Size(78, 16);
                this.checkBox1.TabIndex = 0;
                this.checkBox1.Text = "checkBox1";
                this.checkBox1.UseVisualStyleBackColor = true;
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(299, 450);
                this.Controls.Add(this.groupBox1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.groupBox1.ResumeLayout(false);
                this.groupBox1.PerformLayout();
                this.ResumeLayout(false);        }        #endregion        private System.Windows.Forms.GroupBox groupBox1;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.CheckedListBox checkedListBox2;
            private System.Windows.Forms.CheckedListBox checkedListBox1;
            private System.Windows.Forms.ComboBox comboBox2;
            private System.Windows.Forms.ComboBox comboBox1;
            private System.Windows.Forms.CheckBox checkBox4;
            private System.Windows.Forms.CheckBox checkBox3;
            private System.Windows.Forms.CheckBox checkBox2;
            private System.Windows.Forms.CheckBox checkBox1;
        }
    }
      

  2.   

    //form1.cs
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
        }
    }
      

  3.   

    根据combobox、checkedlistbox、checkbox提供的信息,用代码来写查询语句,然后执行
      

  4.   

    简单!例子:checkedlistbox1.gotfocus 事件combobox1.visible =true;
         checkedlistbox2.gotfocus 事件combobox2.visible=true;     checkedlistbox1.SelectIndexChanged(object sender,EventArgs e)
         {
            try
            {
               con.open (                    
    @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\表名.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True""
                        )//连接数据库;           SqldataApdater da=new SqldataApdater("select 字段 from 表 where 标示字段='"+this.checkedListBox1.SelectedValue.tostring()+"'",con)
               dataset ds=new dataset();
               da.fill(ds);
               combobox1.datasource=ds.tables[0];
               combobox1.displaymenber="字段名";
               combobox1.valuemenber="字段名";
               con.close();
            }     
            catch{}     }