SQLITE - INSERT不返回错误但未插入数据

时间:2010-06-14 20:45:34

标签: c# database sqlite

我正在尝试将数据从C#应用程序插入到本地SQLITE数据库文件中。事务不会抛出任何错误,但不会插入数据。相同的insert语句在查询分析器中起作用。

我需要执行提交吗?有提交方法吗?

Command的事务属性为null ..

  var command = new SQLiteCommand(insert.BuildInsert(tableName,keyValuePairs),Connection);

            command.ExecuteNonQuery();

更新:

我还试图将SQLiteCommand与SQLiteTransaction联系起来但没有运气。

try
        {
            SQLiteTransaction liteTransaction = Connection.BeginTransaction();
            SQLiteCommand command = new SQLiteCommand(insert.BuildInsert(tableName, keyValuePairs), Connection);
            command.Transaction = liteTransaction;
            command.ExecuteNonQuery();
            liteTransaction.Commit();
        }
        catch (SQLiteException e)
        {
            //error
            connection.Close();
        }

BuildInsert方法只构造一个INSERT字符串。插入在查询分析器中工作正常。

public  string BuildInsert(string tableName, IDictionary<string, string> testDataDic)
    {
        stringBuilder = new StringBuilder(String.Format("INSERT INTO {0} ", tableName));
        AddColumns(stringBuilder,testDataDic.Keys);
        AddValues(stringBuilder, testDataDic.Values);

        return stringBuilder.ToString();

    }

这是INSERT语句的示例。这在代码之外工作正常,但不会抛出任何错误:

INSERT INTO TestData (walking,running,image,yoga,exercise,meditation,hobby,somethingelse,howoften,numtechniques,userreturn,chosentechnique,chosentechnique)VALUES ("true","I will try to use deep breathing.","false","true","false","false","true","true","When I'm stressed","1","true","deepbreathing","deepbreathing"); COMMIT;

1 个答案:

答案 0 :(得分:0)

DOH!因此,本地数据库构建操作设置为“始终复制”我有相同文件的多个版本。

很抱歉。那太蹩脚了。