早上好先生!我可以使用阅读器从数据库中调用数据,并且在获取数据库中的数据之后,当我获得预期的数据时,它们将显示一个messageBox。这是我的示例代码:
if (textBox5.Text == "")
{ }
else
{
DialogResult ms = MessageBox.Show("Try Again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
if (ms == DialogResult.OK)
{
textBox5.Clear();
textBox1.Clear();
listBox5.Items.Clear();
textBox3.Clear();
listBox4.Items.Clear();
}
}
while (reader.Read())
{
listBox4.Items.Clear();
if (string.Compare(label1.Text, reader.GetString(0)) == 0)
{
for (int t = 1; t < 11; t++)
{
words.Add(reader.GetString(t));
}
}
words.Shuffle();
listBox4.Items.AddRange(words.ToArray());
}
reader.Close();
coon.Close();
我的问题是,当我应用这些代码时,将出现两个messageBox,因此我将其删除:
textBox5.Clear();
textBox1.Clear();
listBox5.Items.Clear();
textBox3.Clear();
listBox4.Items.Clear();
我想要的只是想一次显示messageBox。你能帮我吗?
您没有显示足够的代码,但我将假定此函数在TextChanged
事件内。
如果真是这样,您将检查是否TextBox5
有一些文本,然后清除表单上的许多控件。您还没有显示其他事件及其活动,因此在这一点上很难告诉您更多信息。
考虑调试代码并逐行进行调试,这样您就可以遵循程序流程的逻辑并查看发生打...的地方...
我还要更改前3行:
if (textBox5.Text == "")
{ }
else
with if (!string.IsNullOrEmpty(this.textBox5.Text.Trim()))
,这意味着如果string不为空(确切地说为null或为空)。
希望这可以帮助。
祝好运
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句