如何只搜索所选位置,当我在文本框中键入字母时,他只能从组合框中所选项目的位置进行搜索,但是如果我选择位置并在其中键入字母a,我的文本框甚至可以搜索我想要的其他位置在我的文本框中,数据网格选择位置和姓氏的第一个字母,例如:
if (string.IsNullOrEmpty(textBox1.Text))
{
MySqlDataAdapter sda = new MySqlDataAdapter("Select * from employee where Pstatus='Active'", con);
DataTable data = new DataTable();
sda.Fill(data);
dataGridView1.DataSource = data;
}
else
{
MySqlDataAdapter sda = new MySqlDataAdapter("SELECT `empID`, `FirstName`, `MiddleName`, `LastName`, `Gender`, `Address`, `Zipcode`, `Position`, `Rate`, `DateHired`, `TelNo`, `empSched`, `Pstatus`, `AllowanceID`, `image`, `Red` FROM `employee` WHERE FirstName LIKE '" + textBox1.Text + "%' OR MiddleName LIKE '" + textBox1.Text + "%' OR LastName LIKE '" + textBox1.Text + "%' AND Position LIKE '" + comboBox1.Text + "%' ", con);
DataTable data = new DataTable();
sda.Fill(data);
dataGridView1.DataSource = data;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
MySqlDataAdapter sda = new MySqlDataAdapter("SELECT `empID`, `FirstName`, `MiddleName`, `LastName`, `Gender`, `Address`, `Zipcode`, `Position`, `Rate`, `DateHired`, `TelNo`, `empSched`, `Pstatus`, `AllowanceID`, `image`, `Red` FROM `employee` WHERE Position LIKE '" + comboBox1.Text + "%' ", con);
DataTable data = new DataTable();
sda.Fill(data);
dataGridView1.DataSource = data;
}