views:

48

answers:

1

I am attempting to insert data into a local SQLITE database file from a C# application. The transaction does not throw any errors but the data is not inserted. The same insert statement works from within a query analyzer.

Do I need to perform a commit? Is there a Commit method?

Command's transaction property is null..

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

            command.ExecuteNonQuery();

UPDATE:

I have also tried to assciate my SQLiteCommand with a SQLiteTransaction but have had no luck.

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();
        }

The BuildInsert method just constructs a string that is the INSERT. The insert works fine in a query analyzer.

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();

    }

This is an example of the INSERT statement. This works fine outside of the code but does not throw any errors:

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;
A: 

DOH! So the local database build operation was set to 'Always copu' I have multiple versions of the same file.

Sorry for that. That's lame.

Nick