Question

I have a list of items that I want to insert into the database but I do not want any duplicates. So I delete all the items and reinsert all. It's not the most efficient way but it's not many items so it works for me. But I get syntax error near "Insert". I do the following:

DELETE FROM Settings WHERE Type = 'Extensions'
INSERT INTO Settings (Value, Type) Values ('img', 'Extensions')
INSERT INTO Settings (Value, Type) Values ('avi', 'Extensions')
INSERT INTO Settings (Value, Type) Values ('mpg', 'Extensions')
INSERT INTO Settings (Value, Type) Values ('mkv', 'Extensions')
INSERT INTO Settings (Value, Type) Values ('mov', 'Extensions')
INSERT INTO Settings (Value, Type) Values ('iso', 'Extensions')

And execute it with this:

protected bool ExecuteCommand(string command, bool rollbackOnError)
{
    using (SQLiteTransaction transaction = DbConnection.BeginTransaction())
    {
        try
        {

            using (SQLiteCommand mycommand = new SQLiteCommand(DbConnection))
            {
                mycommand.CommandText = command;
                mycommand.ExecuteNonQuery();
                transaction.Commit();
            }
        }
        catch
        {
            if (rollbackOnError)
            {
                transaction.Rollback();
            }
            return false;
        }
    }
    return true;
}
Was it helpful?

Solution

You need to separate your commands with a semicolon, don't you?

Also I am not sure if the command is able to run multiple statements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top