1、后台在使用sql语句in时,前端数据例如字段值是1,2,3
这时就需要先把该字符串转成数组的然后在进行拼接
string str = "1,2,3,4,5,6,7"; string[] strArray = str.Split(','); //字符串转数组 str = string.Empty; str = string.Join(",", strArray);//数组转成字符串 sbWhere.AppendLine(" AND c.PROJECTID IN('" + string.Join("','", strArray) + "')");
或者
var tt = string.Format(@"AND ILLEGALTYPENO IN ('{0}')", str.Replace(",", "','"));