我在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;
}
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count == 0)
{
display your message that no rows returned
}
else {
display rows returned
}
享受