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)
熱點內容