代码之家  ›  专栏  ›  技术社区  ›  Tom Gullen

不使用ExecuteCommand的参数化查询

  •  0
  • Tom Gullen  · 技术社区  · 6 年前

    给定查询:

    db.ExecuteCommand(
        "UPDATE ForumUserStats SET Posts += {0} WHERE UserID = {1} AND ForumID = {2}",
         -1, post.AuthorID, post.Forum.ID
    );
    

    StringBuilder 然后在一个 ExecuteCommand 陈述。

    如何将上面这样的查询添加到字符串中,以便在以后执行,而不必 DataContext 有空吗?

    请注意, string.format 没有正确地将SQL的属性参数化(例如 DateTime strings ).

    0 回复  |  直到 6 年前