我在政府领域插入了大约18个城市,我可以通过ID搜索我想要的每个城市,但是现在我想在组合框中选择任何东西时,通过ID搜索所有城市。
MSDN
答案 0 :(得分:0)
如果“未选择任何内容”
,您可以更改语句if (ComboBox.Text == string.Empty)
{
cmd.CommandText = "select * from Person where ( PER_ID = '" + a + "')";
}
说明:
string sCity = "%";
等变量名称代替string c = "%";
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.
}