This is what I use so that the enter button starts the search. It works, but it triggers a system beep. I have no idea why.
private void searchbox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { searchbutton.PerformClick(); } else {
This happens as soon as I press the enter button, and not some other line in the code. Thoughts on what I am missing?
Here's the searchbutton_Click:
private void searchbutton_Click(object sender, EventArgs e) { var searchvar = searchbox.Text; SqlParameter var1 = new SqlParameter(@"var1", SqlDbType.Text); var1.Value = "%" + searchvar + "%"; var conn = new SqlConnection("Data Source=TX-MANAGER;Initial Catalog=Contacts;Integrated Security=True"); var comm = new SqlCommand(@"SELECT [Name ID], First, Last, Address, City, State, ZIP FROM contacts WHERE (First LIKE @var1) OR (Last LIKE @var1)", conn); if (checkBox1.Checked == true) { comm.CommandText += "ORDER BY ZIP"; } else {
source share