将list集合转化为sql in 的范围对象 比如 List<string> idList= new List<string>(); idList.Add(“001”); idList.Add(“002”); idList.Add(“003”); select * from table where id in (‘001’,‘002’,‘001’) 公共方法 /// <summary> /// C#实现把String字符串转化为SQL语句中的In后接的参数 /// </summary> /// <param name="aa"></param> /// <returns></returns> public static string ToSqlListString(List<string> guidList) { StringBuilder sqlString = new StringBuilder(); foreach (string item in guidList) { sqlString.AppendFormat("'{0}',", item); } string result = sqlString.ToString(); return result.Trim(','); }
标签:idList,C#,List,list,Add,sqlString,sql,string From: https://www.cnblogs.com/51net/p/17112633.html