C#拼接SQL中in条件

 

 
一、拼接字符串类型的字段

string sql = @"select distinct ziduan from tablename where ziduan in ('{0}')";

sql=string.Format(sql, string.Join("','", list.ToArray()));

二、拼接数字类型的字段

string sql = @"select distinct ziduan from tablename where ziduan in ({0})";

sql=string.Format(sql, string.Join(",", list.ToArray()));

 

posted @ 2020-07-24 18:33  八英里  阅读(2607)  评论(0编辑  收藏  举报