查看如何编写弹出消息“未找到记录”

本文关键字:记录 未找到记录 消息 何编写 | 更新日期: 2023-09-27 18:12:57

当搜索结果为0时,我在软件中编写了一个搜索函数。它没有给我任何弹出窗口或任何消息。如何处理这种情况我的代码如下:

我需要任何消息弹出,它显示没有数据从我的表。

      `private void cncInfoBindingNavigatorSaveItem_Click(object sender, EventArgs e)
         {
        this.Validate();
        this.cncInfoBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.cncDataSet1);
       }
    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'cncDataSet1.CncInfo' table. You can move, or remove it, as needed.
        this.cncInfoTableAdapter.Fill(this.cncDataSet1.CncInfo);
        timer1.Start();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        this.cncInfoBindingSource.AddNew();
    }
    private void button2_Click(object sender, EventArgs e)
    {
        this.Validate();
        this.cncInfoBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.cncDataSet1);
    }
    private void button3_Click(object sender, EventArgs e)
    {
        this.cncInfoBindingSource.RemoveCurrent();
    }
    int count = 0;
    private void timer1_Tick(object sender, EventArgs e)
    {
            count = cncInfoBindingSource.Count;
            label_status.Text = "Records Found: " + count.ToString();
            if (count < 2)
            {
                Next_btn.Visible = false;
                Previous_btn.Visible = false;
            }
            else if (count <= 0)
            {
                MessageBox.Show("No records found ");
            }
            else
            {
                Next_btn.Visible = true;
                Previous_btn.Visible = true;
            }
    }
    private void Next_btn_Click(object sender, EventArgs e)
    {
        cncInfoBindingSource.MoveNext();
    }
    private void Previous_btn_Click(object sender, EventArgs e)
    {
        cncInfoBindingSource.MovePrevious();
    }
    private void button4_Click(object sender, EventArgs e)
    {
        this.cncInfoTableAdapter.SearchFileName(this.cncDataSet1.CncInfo, textBox1.Text);
    }
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    }
    private void button5_Click(object sender, EventArgs e)
    {
        this.cncInfoTableAdapter.SearchFileName(this.cncDataSet1.CncInfo, textBox1.Text);
    }
            }
          }
           `

查看如何编写弹出消息“未找到记录”

在计时器上显示消息框是很难看的。

然而,对于你要求帮助的问题:

你的代码是:if (count <2) {//隐藏按钮}其他如果(计数& lt; = 0) {/显示消息/}

消息框将永远不会显示,因为0 <2 .代码只是隐藏按钮

try:

if(cncInfoTableAdapter.GetData().Rows.Count < 1) MessageBox.Show("whatever");