当在 C# Windows 窗体中找不到搜索结果时,如何显示找不到记录的消息

How do i show record not found message when serach result not found in c# windowsforms

    try
    {
        SqlConnection con = new SqlConnection("data source=DESKTOP-28VA3GI;database=EMPLOYEES;integrated security=true");
        SqlCommand cmd = new SqlCommand("select * from emp where ename like '" + textBox1.Text + "%' or eno like '" + textBox1.Text + "%' or phone like '" + textBox1.Text + "%'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "e");
        dataGridView1.DataSource = ds;
        dataGridView1.DataMember = "e";
    }
    catch ( )
    {

    }

您要同时获取多个 table 吗?如果是,那么您可以使用数据集,否则您可以使用数据table.

如果您选择数据集,您可以使用 ds.Tables(i).Rows.Count 在 table 中找到行数。 (i --> 您要检查的 table 的索引)。

如果您选择数据table (dt),您可以通过 dt.Rows.Count.

找到行数

根据结果您可以显示您的消息。