Update and then select Sqlite query does not return updated value

I have written an application in that I am using SQLite(System.Data.SQLite .Net Version). Every thing is working fine. But I am observing a strange behaviour.

I update a column value and then in the next line when I try to read the content then it gives the old value not the updated value. I checked the rows affected, value is proper(It returns rows affected as 1). But when I try to read the content then it gives the old value.

Code to update the content.

string queryCommand = UPDATE metadata SET ischanged = 1 WHERE path = 'c:Temp'
using (SQLiteCommand sqlCommand = new SQLiteCommand(queryCommand, dbConnection))
{
    using (SQLiteTransaction sqlTransaction = 
           dbConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
    {
        sqlCommand.Transaction = sqlTransaction;        
        rowsAffected = sqlCommand.ExecuteNonQuery();
        sqlTransaction.Commit();
    }
}

Code to read the content.

string queryCommand = "SELECT id FROM metadata WHERE path = 'c:Temp' AND ischanged = 1";
SQLiteDataReader reader = null;
using (SQLiteCommand sqlCommand = new SQLiteCommand(queryCommand, dbConnection))
{
    reader = sqlCommand.ExecuteReader();
}

// Here it returns always 0.
bool isDataPresent = reader.Read();

When I execute the 2nd query, it does not return any value.

I want to know why I am observing this behaviour.


Source: .net

Leave a Reply