我的网站在虚拟数据库中搜索押韵。在代码中,如果文本框是 != 进行搜索,否则显示错误,但是,即使搜索框中没有任何内容,它也会显示结果。这是为什么?
protected void Page_Load(object sender, EventArgs e)
{
ListBox1.Items.Clear();
if (Page.PreviousPage != null)
{
TextBox SourceTextBox =
(TextBox)Page.PreviousPage.FindControl("TextBox1");
if (SourceTextBox != null)
{
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT kelimeler FROM kelimelerim WHERE kelimeler LIKE @searchkey", cnn);
cmd.Parameters.AddWithValue("@searchkey", "%" + SourceTextBox.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
ListBox1.Items.Add(dr.GetString(0));
}
}
cnn.Close();
}
else
{
ListBox1.Items.Add("Lütfen bir harf giriniz");
}
}
}