測試代碼: 效果: 對checkedComboBoxEdit的多值進行SQL查詢時,查詢中使用IN語句,IN裡面第一個條件後面的所有條件的前面都會多出一個空格,導致查詢不正確 需將空格去掉再傳入SQL查詢: ...
測試代碼:
1 public partial class Form1 : Form 2 { 3 public Form1() 4 { 5 InitializeComponent(); 6 } 7 8 private void Form1_Load(object sender, EventArgs e) 9 { 10 List<string> list = new List<string>(); 11 list.Add("小明"); 12 list.Add("小紅"); 13 list.Add("小李"); 14 this.checkedComboBoxEdit1.Properties.DataSource = list; 15 } 16 17 private void checkedComboBoxEdit1_EditValueChanged(object sender, EventArgs e) 18 { 19 if (this.checkedComboBoxEdit1.Text != "") 20 { 21 this.textEdit1.Text = this.checkedComboBoxEdit1.Text; 22 this.textEdit2.Text = string.Format("select * from tableA where name in ('{0}')", this.checkedComboBoxEdit1.Text).Replace(",","','"); 23 } 24 } 25 }
效果:
對checkedComboBoxEdit的多值進行SQL查詢時,查詢中使用IN語句,IN裡面第一個條件後面的所有條件的前面都會多出一個空格,導致查詢不正確
需將空格去掉再傳入SQL查詢:
Replace(",","','") 改為 Replace(", ","','")