I have a problem. I am trying to get a value (string) from my database. Here is the code I am calling to get the value:
public string SelectValueFromTableSettings(string name)
{
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Settings.db")))
{
return connection.Query<SettingDb>("SELECT Value FROM SettingDb WHERE Name=?", name).ToString();
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return null;
}
}
And here is the code to assign the value to a variable:
string SwitchValue = MainActivity.db.SelectValueFromTableSettings(mItems[position].Name);
I am supposed to get a value like Nick or Steve, but I get this as value:
System.Collections.Generic.List`1[CryptoCurrencies.SettingDb]
What am I doing wrong?
connection.Query<SettingDb>("..."), you're callingToString()on it.connection.Query<SettingDb>()returnsList<SettingDb>. Because there's no sensible stringification ofList<T>, it just has the defaultToString()which returnsGetType().FullNameor whatever. Instead, loop through the list.ToString()on Query result, you are getting the name of the result class which is a list of setting. UseFirstOrDefault()instead ofToString()to the first data in list and use SettingDb properties to get the desired result.