gpt4 book ai didi

c# - 使用 if 语句将组合框值与两个文本框值进行比较

转载 作者:行者123 更新时间:2023-11-30 20:43:54 25 4
gpt4 key购买 nike

我正在使用 C# winforms我有一个带有名为 cmbExport 的组合框和两个文本框 txtDateSendtxtSendNum 的表单组合框从存储过程 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;
}

谢谢

最佳答案

因为没有数字可以同时是 642每个 数字都不同于 642,因此您的 if 语句始终 的计算结果为 true。我认为你打算在那里使用 && 而不是 ||:

if (x != 6 && x != 42 && x != 1042 && string.IsNullOrEmpty(sn)

关于c# - 使用 if 语句将组合框值与两个文本框值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30019578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com