private void btnQuery_Click(object sender, EventArgs e) //查询可以根据多个条件进行查询 { sql = "select * from PmPhone where 1=1 and PhoneDisplay = 'TRUE'"; if (txtPhoneNum.Text == "" && cbbPhoneName.Text == "" && cbbPhoneStage.Text == "" && cbbPhoneStatus.Text == "" && txtPhoneCode.Text == "" && txtPhoneNote.Text == "") { MessageBox.Show("请选择查询条件", "提示"); return; } try { if (txtPhoneNum.Text != "") { sql = sql + " and PhoneNum = '" + txtPhoneNum.Text + "'"; } if (cbbPhoneName.Text != "") { sql = sql + " and PhoneName like'%" + cbbPhoneName.Text + "%'"; } if (cbbPhoneStage.Text != "") { sql = sql + " and PhoneStage ='" + cbbPhoneStage.Text + "'"; } if (cbbPhoneStatus.Text != "") { sql = sql + " and PhoneStatus ='" + cbbPhoneStatus.Text + "'"; } if (txtPhoneCode.Text != "") { sql = sql + " and PhoneCode ='" + txtPhoneCode.Text + "'"; } if (txtPhoneNote.Text != "") { sql = sql + " and PhoneNote like'%" + txtPhoneNote.Text + "%'"; } sql = sql + " order by PhoneID DESC"; PhoneBLL Phonebll = new PhoneBLL(); phones = Phonebll.selByCondition(sql); phoneDataGrid.DataSource = phones; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } this.txtPhoneNum.Clear(); this.cbbPhoneName.Text = ""; }