编程中往往会有需要对某个list的值进行查询的需求,而将一个list作为查询条件,我所知道的有两种方法:

  1.for循环遍历,每次循环一个sql,每次查list中一个条件的数据,最后累加

    ...(最基础的,就不说了,不提倡)

  2.foreach遍历取出所有的list数据,组成(1,2,3,4,5,6,7)的形式,直接加在sql语句中

    string strSql = "SELECT RoadCode,StartM,CreateDate,Level,Status " +
           "FROM Maintain_Event WHERE CreateUserId != '" + userid + "' and " +
           "OrgID in ({0})";
    string ids = "";
    foreach (var item in organizeIds.ToList())
    {
      ids += ",'" + item.ToString() + "'";
    }
    ids = ids.Substring(1);

    strSql = string.Format(strSql, ids);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-10-16
  • 2022-01-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-16
  • 2021-08-24
  • 2022-12-23
相关资源
相似解决方案