如何在组合框中搜索整个城市

时间:2016-10-17 05:54:50

标签: c# combobox

我在政府领域插入了大约18个城市,我可以通过ID搜索我想要的每个城市,但是现在我想在组合框中选择任何东西时,通过ID搜索所有城市。

MSDN

3 个答案:

答案 0 :(得分:0)

如果“未选择任何内容”

,您可以更改语句
if (ComboBox.Text == string.Empty)
{   
    cmd.CommandText = "select * from Person where ( PER_ID = '" + a + "')";
}

说明:

  • 使用string sCity = "%";等变量名称代替string c = "%";
  • 使用sql语句where ( PER_ID = @Person)cmd.Parameters.Add("@Person", SqlDbType.Int32).Value = int.Parse(textBox1.Text);
  • 的参数

答案 1 :(得分:0)

如果我找到了你,那么当你没有选择combobox1时,你不想要GOV_NAME_AR上的where子句。

if( ComboBox.SelectedItem == null ) {
   cmd.CommandText = "select * from Person where ( PER_ID = '" + a + "')";
}

答案 2 :(得分:0)

您可以像这样检查ComboBox.SelectedText:

if (comboBox1.SelectedText=="")
{
//SQL statement should not restrict on the c value
}
else
{
//Use your regular SQL query here.
}