1
I’m trying to run a database check, but it’s not working. I still don’t understand how to do the research based on a criterion, using Sqlite and developing the application using Xamarin.Android.
The function I created is that way:
public Player GetJackpot(string Email) {
try {
using (var conn = new SQLiteConnection(Path.Combine(folder, "Player.db"))) {
var list = conn.Query<Player>("SELECT Jackpot FROM Player WHERE Email = ?", Email);
return GetJackpot(Email);
}
}
catch (SQLiteException err) {
Log.Info ("SQLiteEx: ", err.Message);
return GetJackpot(Email);
}
}
And my class is that way:
public class Player
{
[PrimaryKey, AutoIncrement, Column("Id")]
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public int Jackpot { get; set; } // acertando todas as imagens
public int NoCoins { get; set; }
public Player() { }
}
I am trying to return the value of the "Jackpot" column according to the "Email" but without success! I don’t know if I need to return some list to later create the query or if something is missing in the code.
Can you have more than 1 jackpot per email? or is it unique when you Select with this Where? Because you can at the end of the query user a Singleordefault(). Jackpot and return only the jackpot in string.
– Thiago Loureiro
The jackpot is unique yes, I am incrementing every hit with another function. I will follow your tip to see if it works.
– Ronaldo Mendes
Missing quotes for email comparison in your select. It should look like this:
"SELECT Jackpot FROM Player WHERE Email = '?'"
. Tip: Reads [Ask]. Ideally, you should have a [mcve] (this you gave us), declare the problem and the expected behavior. " I’m trying to ... but unsuccessfully" can mean a lot of things ;D– Diego Rafael Souza
I added the tips and details that were missing, but is not yet functional. I do not know what is missing to generate the query.
– Ronaldo Mendes
Try using Table method instead of Query: Conn. Table<Player>(). Where(p => p.email.Equals(Email)). Firstordefault();
– Raquel Pinheiro
Guys, thanks for the tips! I managed to solve the problem differently and I will post the answer below.
– Ronaldo Mendes