我有一个两个checkBox控件,分别为checkBox1,checkBox2。当checkBox1.Checked和checkBox2.Checked为“true”时,他们后面的文本框TextBox1和TextBox2可以赋值。
然后根据TextBox1和TextBox2的值更新数据库。
若checkBox1.Checked和checkBox2.Checked为“true”,则public void Update(int a,int b, int c)
{
  .........................
  
  string updateString="update Monitor set A=@a,B=@b where C=@c";
  SqlHelper.ExecuteNonQuery(trans, CommandType.Text, updateString,....);
}若checkBox1.Checked和checkBox2.Checked为“true”,则为上面的
updateString="update Monitor set A=@a,B=@b where C=@c";若checkBox1.Checked为false,checkBox2.Checked为“true”,则
string updateString="update Monitor set B=@b where C=@c"若checkBox1.Checked为true,checkBox2.Checked为“false”,则
string updateString="update Monitor set A=@a where C=@c"
问题是我更怎么样写判断语句,来判断checkBox1,checkBox2的两种情况
因为checkBox1,checkBox2属于Form1窗体,public void Update(int a,int b, int c)属于Form2窗体
所以不知道怎么写这种语句,请教各位了?

解决方案 »

  1.   

    把窗体Form1当做参数传递给Form2就ok了
    1:把CheckBox1和CheckBox2定义成Public的
    2:在Fore2中
    private Form1 f1 =null;
    public Form1 getF1
    {
    set
    {
    f1 =value;
    }
    }
    3:
    如果在Form1中
    Form2 f2 = new Form2();
    f2.getF1 = this;
    f2.Show();
    4:再在Form2中判断,if(f1.CheckBox1.Checked).......
      

  2.   

    SQL语句是另一个窗口的,安只需要传3个值,你就传过去就行了啊如果要修改SQL,可以这样Form1里面写string updateString="";
    if (check1.cheked || check2.checked)
    {
    update Monitor set ";if (check1.checked)
    {
    updateString += " A=@a";
    }if (check2.checked)
    {
    updateString += " b=@b";
    }
    updateString += "where C=@c" ;
    }
    但是,光修改SQL肯定不可以,因为它们的参数不一样。如果Form2不是你做的话,你问问做的人要只修改一个的时候应该怎么传参数
      

  3.   

    将checkbox1和checkbox2的选中状态用字符串表示,比如“01”或者“11”,“00”“10”等等,将这个字符串传递给form2,form2再对这个字符串解析,就可以实现啦~
      

  4.   

    提供一个思路:若checkBox1.Checked 产生一个SESSION["cK1"],若checkBox2.Checked 产生一个SESSION["cK2"],
    然后在Form2窗体 里面去访问SESSION["cK1"],SESSION["cK2"], 来确定updateString的值.
      

  5.   

    把public void Update(int a,int b, int c)写到form1中直接传参然后调用啊,
    你再说明白一点
    如果只是单纯判断,直接
    if(checkBox1.Checked)
    {
    if(checkBox2.Checked)
    {
    //checkBox1.checkBox2都被选中
    }
    else
    {
    //只有checkBox1被选中
    }
    }
    else
    {
    if(checkBox2.Checked)
    {
    //只有checkBox2被选中
    }
    //都没被选中
    }