1

I am working with Xamarin forms and I have implemented SQLite database using Sqlite-net-pcl nuget package. The problem is that the database is initially saving a row but is unable to update or delete any row. Here is the code in which I save and delete the database row with a Key.

    public Task<int> SaveItemAsync(SQLiteRowData item)
    {
        if (item.ID != 0)
        {
            return database.UpdateAsync(item);
        }
        else
        {
            return database.InsertAsync(item);
        }
    }
     public Task<int> DeleteItemAsync(SQLiteRowData item)
    {
        return database.DeleteAsync(item);
    }

    public Task<int> DeleteItemAsyncWithKey(string key)
    {
        Task<SQLite.SQLiteRowData> lSQLiteRowTaskData = 
        App.sqliteConnectionPath.GetItemForKeyAsync(key);
        SQLite.SQLiteRowData lSQLiteRowData  = lSQLiteRowTaskData.Result;
        return database.DeleteAsync(lSQLiteRowData);
    }

    public async Task<bool> DeleteUserPreferencesAsync()
    {
        Boolean lReturnValue = false;

        try
        {
            Task<SQLiteRowData> lSQLiteRowDataTask = App.sqliteConnectionPath.GetItemForKeyAsync("UserPreferences");                SQLiteRowData lSQLiteRowData = lSQLiteRowDataTask.Result;
            if (lSQLiteRowData != null) {
                await DeleteItemAsync(lSQLiteRowData);
                lReturnValue = true;
            }
        }
        catch (Exception ex)
        {
            EMAUtilities.printLogs(ex.Message);
        }
        return lReturnValue;
    }

   // Used for saving userpreference
   SQLiteRowData lSQLiteRowData = new SQLiteRowData("UserPreferences", lValue);
   Task<int> x = SaveItemAsync(lSQLiteRowData);

Can anyone point out the mistake I have done in this, Thanks in advance

Anshuman Singh
  • 1,018
  • 15
  • 17
  • Are You receiving some error? Or is it just "no rows updated/deleted" and task itself returns 0? – Tatranskymedved Jan 05 '18 at 07:09
  • I am not receiving any error, it is just showing the initial value which I have saved instead of new value. I case of delete it returns 1 but I still get the row value instead of getting null. – Anshuman Singh Jan 05 '18 at 07:39

0 Answers0