.net在使用存储过程中IN参数的拼接方案,使用Join()方法

有时候拼接SQL语句时,可能会需要将list中的元素都加上单引号,并以逗号分开,但是Join只能简单的分开,没有有单引号!

1.第一种拼接方案
cs 复制代码
List<string> arrIds = new List<string>();
arrIds.Add("aa");
arrIds.Add("bb");
arrIds.Add("cc"); ;
string arrIdsed = string.Join(",", arrIds.Select( i => "'" + i + "'" ));
Console.WriteLine(arrIdsed);
2.第二种解决方案
cs 复制代码
StringBuilder builder = new StringBuilder();
builder.Append("'");
List<string> arrIds = new List<string>();
arrIds.Add("aa");
arrIds.Add("bb");
arrIds.Add("cc"); ;
string arrIdsed = string.Join("','", arrIds);
builder.Append(arrIdsed).Append("'");
Console.WriteLine(builder);
相关推荐
工作中的程序员4 分钟前
ES 索引或索引模板
大数据·数据库·elasticsearch
严格格7 分钟前
三范式,面试重点
数据库·面试·职场和发展
微刻时光24 分钟前
Redis集群知识及实战
数据库·redis·笔记·学习·程序人生·缓存
单字叶33 分钟前
MySQL数据库
数据库·mysql
mqiqe37 分钟前
PostgreSQL 基础操作
数据库·postgresql·oracle
just-julie39 分钟前
MySQL面试题——第一篇
数据库·mysql
趋势大仙1 小时前
SQLiteDatabase insert or replace数据不生效
android·数据库
丁总学Java1 小时前
如何使用 maxwell 同步到 redis?
数据库·redis·缓存
爱吃南瓜的北瓜1 小时前
Redis的Key的过期策略是怎样实现的?
数据库·redis·bootstrap
一心只为学1 小时前
Oracle密码过期问题,设置永不过期
数据库·oracle