5/25/2018 4:11:10 AM
Viewed: 64
tamkhong
2/5/2013 4:59:47 PM
C#: Avoiding Performance Issues with Inserts in SQLite
Wrap BEGIN \ END statements around your bulk inserts. Sqlite is optimized for transactions.


string insertString = "INSERT INTO [TableName] ([ColumnName]) Values (@value)";

SQLiteCommand command = new SQLiteCommand();
command.Parameters.AddWithValue("@value", value);
command.CommandText = insertString;
command.Connection = dbConnection;
SQLiteTransaction transaction = dbConnection.BeginTransaction();
try
{
    //---INSIDE LOOP
    SQLiteCommand sqlComm = new SQLiteCommand(sqlQuery, dbcon);
    nRowUpdatedCount = sqlComm.ExecuteNonQuery(); 
    //---END LOOP

    transaction.Commit();
    return true;
}
catch (SQLiteException ex)
{
    transaction.Rollback();
}

Gửi trả lời