Frage

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;

    }
War es hilfreich?

Lösung

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

enjoy

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top