sqlinlinq
发布时间: 2024-04-04 23:49:42
A. C#代码处理SQL语句中in操作
//将list转化为形如“1,2,3,4”这样的字符串
public static string ConvertToStr(IList<string> list)
{
try
{
var sb = new StringBuilder();
foreach (var t in list)
{
sb.Append("'");
sb.Append(t);
sb.Append("'");
sb.Append(",");
}
if (sb.Length > 0)
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
catch (Exception)
{
return "";
}
}
查询的时候:
var inStr=ConvertToStr(list);
var select=string.Format("select * from table where id in ({0})",inStr)
热点内容