首页 > 其他 > 详细

CheckedComboBoxEdit 多选时,值与值之间会多出一个空格

时间:2017-11-09 13:40:52      阅读:669      评论:0      收藏:0      [点我收藏+]

测试代码:

 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(", ","‘,‘")

 

CheckedComboBoxEdit 多选时,值与值之间会多出一个空格

原文:http://www.cnblogs.com/huangchuxian/p/7808325.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!