我正在使用 C# winforms
我有一个带有名为 cmbExport
的组合框和两个文本框 txtDateSend
和 txtSendNum
的表单
组合框从存储过程 GET_ALL_EXPORT_WITHNULL
获取数据
cmbExport.DataSource = cmp.GET_ALL_EXPORT_WITHNULL();
cmbExport.DisplayMember = "side";
cmbExport.ValueMember = "ID_EXPORT";
cmbExport.SelectedValue = "6";
当用户未从组合框中选择某些值并且其中一个文本框为空时,会出现一个消息框
我尝试了这段代码,但它不起作用:
int x = Convert.ToInt32(cmbExport.SelectedValue); //Its already integer but the code didn't accept int x = cmbExport.SelectedValue; ???
string ds = txtDateSend.Text;
string sn = txtSendNum.Text;
if ((x != 6 || x != 42 || x != 1042) && string.IsNullOrEmpty(sn))
{
MessageBox.Show("you should enter a send number");
return;
}
else if ((x != 6 || x != 42 || x != 1042) && string.IsNullOrEmpty(ds))
{
MessageBox.Show("you should enter a date send);
return;
}
谢谢
最佳答案
由于没有数字可以同时是 6
和 42
,因此每个数字都不同于 6
或 42
,因此您的 if
语句始终计算结果为 true。我认为您打算在那里使用 &&
而不是 ||
:
if (x != 6 && x != 42 && x != 1042 && string.IsNullOrEmpty(sn)
关于c# - 使用 if 语句将组合框值与两个文本框值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30019578/