Reputation: 147
I have the following code in aspx file. I would like to display a message when my query returns 0 rows or null. How can I check this correct since my example does not catch null values.
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;
}
Upvotes: 0
Views: 533
Reputation: 354
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count == 0)
{
display your message that no rows returned
}
else {
display rows returned
}
enjoy
Upvotes: 1