.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);
相关推荐
张铁铁是个小胖子3 小时前
redis执行lua脚本的原子性和数据库原子性的区别
数据库·redis·lua
源图客3 小时前
Spark读取MySQL数据库表
数据库·mysql·spark
xiucai_cs5 小时前
MySQL深分页慢问题及性能优化
数据库·mysql·性能优化·深分页
当牛作馬5 小时前
ES常用查询命令
数据库·mysql·elasticsearch
fs哆哆5 小时前
在VB.net中一维数组,与VBA有什么区别
java·开发语言·数据结构·算法·.net
提笔惊蚂蚁5 小时前
终端VS命令解释器(Linux & Windows)
linux·运维·windows
chenglin0167 小时前
ES_索引的操作
大数据·数据库·elasticsearch
昏睡红猹7 小时前
从0.99到1实现一个Windows上的虚拟hid键盘设备
windows·windows driver
共享家95278 小时前
MYSQL库及表的操作
数据库