C # sql operator doesn't seem to work
Hello good afternoon. I have a small question on how to describe sql / C #, I cannot figure out why my code is not working.
if (Combo_List.Text == "What")
{
listView1.Items.Clear();
myds.Clear();
mydaEvents.SelectCommand = myconn.CreateCommand();
mydaEvents.SelectCommand.CommandText = "select * from Eventstbl where What like '@what%'";
mydaEvents.SelectCommand.CommandType = CommandType.Text;
mydaEvents.SelectCommand.Parameters.Add("@what", SqlDbType.NVarChar, 2000, "What").Value = text_Search.Text;
mydaEvents.Fill(myds, "Eventstbl");
foreach (DataRow item in myds.Tables["Eventstbl"].Rows)
{
ListViewItem items = new ListViewItem(item["EventsID"].ToString());
items.SubItems.Add(item["What"].ToString());
listView1.Items.Add(items);
}
}
@ what% won't work, but when I put "%" all items that start with the letter a are shown in my list view1. I don't know how to fix this problem. Help me please. Thank you in advance.
+3
source to share
2 answers