做N个CheckBox,CheckBox的Name是数据库中列的名称,Text则是要在GirdView中的列名
代码如下  希望大家给兄弟点思路EmployeeName.Name = EmployeeName; //EmployeeName 是 CheckBox
EmployeeName.Text = 姓名;EmployeeSex.Name = EmployeeSex;
EmployeeSex.Text = 性别;string strsql = "select ";
string strsql2 = "from person";
foreach(Control c in this.Controls)
{
  if (c is CheckBox)
  {
                    
  }
}

解决方案 »

  1.   

    如果是checkbox 取他的name和text  拼接一个sql查询
      

  2.   

    补充在被选中的情况下 取他的name和text 拼接一个sql查询
      

  3.   

    就在sql语句中调用它们的值就好了啊
      

  4.   

    调用会啊  拼接起来 没思路啊string str ;
                string sql = "select ";
                string sql2 = "from 表";
                SqlDataAdapter sda = new SqlDataAdapter(sql+ str+ sql2,con);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];            foreach (Control c in this.Controls)
                {
                    switch (c is CheckBox)
                    {
                        case EmployeeID.Checked:
                            str = EmployeeID.Name + " as " + EmployeeID.Text;
                        case EmployeeName.Checked:
                            str = EmployeeName.Name + " as " + EmployeeName.Text;
                    }
                }
      

  5.   

                switch (c is CheckBox)
                {
                        CheckBox cb= c as CheckBox;
                    case cb.Checked:
                   //logic code
                }
      

  6.   

    if(c is CheckBox)
                    {
      //拼接sql 语句,执行你的操作