How to edit items in sqlite.net with xamarin [closed]

-1

I'm learning to use sqlite.net in Xamarin , but at the time of editing an item is not working, I debugged the code and gave breakpoint to EditItens() and saw values passed to conexao.Query<Itens> are correct, but the ones received in the variable Teste below remain the same as previously, I'm missing something when editing the values in sqlite? There may also be something wrong with GetItens() , but I find it kind of difficult because it works normally when used to grab values and show in ListView of MainActivity . Below the above methods

string pasta = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
public List<Itens> GetItens()
    {
        try
        {
            var conexao = new SQLiteConnection(System.IO.Path.Combine(pasta, "Itens.db3"));
            return conexao.Table<Itens>().ToList();
        }
        catch (Exception)
        {
            return null;
        }
    }

public bool EditItens(Itens itens)
    {
        try
        {
            var conexao = new SQLiteConnection(System.IO.Path.Combine(pasta, "Itens.db3"));
            conexao.Query<Itens>("UPDATE Itens set Nome=?,Preco=? Where Id=?", itens.Nome, itens.Preco, itens.Id);
            Teste = GetItens();
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

If you can tell me where I can find pasta, "Itens.db3" by Windows File Explorer, it will also help because I can verify that the item is not actually being edited.

    
asked by anonymous 14.10.2017 / 00:41

1 answer

1

Anderson, use this in updating the data:

var conexao = new SQLiteConnection(System.IO.Path.Combine(pasta, "Itens.db3"));
            conexao.Execute("UPDATE Itens set Nome=?,Preco=? Where Id=?", 
itens.Nome, itens.Preco, itens.Id);

Optionally and preferably, since you have the items object, use this:

conexao.Update(itens);

Your database will be located on your smartphone, in the folder that was set to

var conexao = new SQLiteConnection(System.IO.Path.Combine(pasta, "Itens.db3"));
    
14.10.2017 / 02:14