C#拼接SQL中in条件

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-01-02 16:30  紫陌红尘520  阅读(686)  评论(0编辑  收藏  举报