0

我在 aspx 文件中有以下代码。当我的查询返回 0 行或 null 时,我想显示一条消息。我如何检查这个是否正确,因为我的示例没有捕获空值。

        protected void search_Click(object sender, EventArgs e)
    {
        string searchItem;
        searchItem = "Select * FROM test WHERE (name like '%"+searchTxt.Text.ToString()+"%')";
        SqlDataSource.SelectCommand = searchItem;    
        if (SqlDataSource.SelectCommand == null)
            hiddenMsg.Visible = true;
        else
            SqlDataSource.SelectCommand = searchItem;

    }
4

1 回答 1

1
int count = Convert.ToInt32(cmd.ExecuteScalar());
        if (count == 0)
        {
             display your message that no rows returned
        }
        else {
           display rows returned
       }

请享用

于 2012-11-20T10:37:20.173 回答