我有以下两个陈述:

db2.Execute(" UPDATE CLICKHISTORY SET " +
            " DAYOFYEAR = " + dayOfYear + " , " +
            " YEAR = " + year + " , " +
            " MONTH = " + month + " , " +
            " DAY = " + day + " , " +
            " BTNACOUNT = BTNACOUNT + 1 WHERE YYMMDD = " + yymmdd );
db2.Execute(" INSERT INTO CLICKHISTORY " +
            " (YYMMDD,DAYOFYEAR,YEAR,MONTH,DAY,BTNACOUNT) " +
            " VALUES ( " +
              yymmdd + " , " +
            dayOfYear + " , " +
            year + " , " +
            month + " , " +
            day + " , " +
            "1) WHERE changes() = 0");

我想做的是在运行第二条语句之前检查第一条语句中的changes()= 0。

谁能告诉我如何将这两个语句组合为一个,以便检查changes()的值?

最佳答案

假设db2的类型为SQLite.SQLiteConnection,则可以使用Execute方法的返回值找出受影响的行数-类似于:

int rowsAffected = db2.Execute("UPDATE...");
if (rowsAffected == 0) {
    rowsAffected = db2.Execute("INSERT...");
}

关于c# - 如何合并在C#中运行的两个SQLite语句?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46690822/

10-10 23:29
查看更多