我有一个两个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窗体
所以不知道怎么写这种语句,请教各位了?
然后根据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窗体
所以不知道怎么写这种语句,请教各位了?
解决方案 »
- 问个关于c#读取Excel后一个简单的问题
- 有哪位高手在C#中使用过Xtreme Suite Pro ActiveX v9.60,有问题请教,在线等急.............
- 如何去除数值字符串后面 0 ?
- 还是事务的问题
- 一个小问题,String和string有什么区别
- 关于如何将程序添加到“控制面板”中的“添加删除”程序那个模块里面?
- 如何取得局域网内计算机运行程序的列表?
- 一个事件的问题,请高手来帮忙。
- [急]怎么把一个ActiveX控件放到WinForm上面啊?
- C#如何实现将Excel数据导入到MySql中
- 请问C#中treeview删除选中节点的所有子节点的函数是什么?
- TreeView的使用(c#、ASP。Net中用递归算法实现对数据的增删改,用c#语言,ASP。Net做)
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).......
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不是你做的话,你问问做的人要只修改一个的时候应该怎么传参数
然后在Form2窗体 里面去访问SESSION["cK1"],SESSION["cK2"], 来确定updateString的值.
你再说明白一点
如果只是单纯判断,直接
if(checkBox1.Checked)
{
if(checkBox2.Checked)
{
//checkBox1.checkBox2都被选中
}
else
{
//只有checkBox1被选中
}
}
else
{
if(checkBox2.Checked)
{
//只有checkBox2被选中
}
//都没被选中
}