locked
SQL-Lite Returning query to Entry RRS feed

  • Question

  • User396669 posted

    Hello,is it possible to return a value from sql table to entry by method? I try to do it this way, but entry only prints "system.thread ....." instead of a valid value.

    `public class TableName {

        [PrimaryKey, AutoIncrement, NotNull]
        public long TableValue{ get; set; }
    }`
    

    Table is empty, but it should load 0 to the entry at the beginning

    My method public Task<TableName> TableNameLoad(int TableValue)
    { return _database.Table<KalorieTeraz>().Where(i => i.TableValue== TableValue).FirstOrDefaultAsync(); }

    MainPage: Entry.Text = await App.Database.TableNameLoad();

    I cannot find a solution

    Tuesday, November 10, 2020 1:19 PM

All replies

  • User382871 posted

    I try to do it this way, but entry only prints "system.thread ....." instead of a valid value. The 'TableNameLoad' method returns a value which is type of Task<TableName>. The value of Entry.Text should be a string. pass a string type attribute of the 'TableName' class instead of the class object.

    Try the following code: ``` var tableName = await App.Database.TableNameLoad().Result;

    Entry.Text = tableName.PropertyA; ```

    Tuesday, November 10, 2020 2:20 PM
  • User396669 posted

    @Jarvan said:

    I try to do it this way, but entry only prints "system.thread ....." instead of a valid value. The 'TableNameLoad' method returns a value which is type of Task<TableName>. The value of Entry.Text should be a string. pass a string type attribute of the 'TableName' class instead of the class object.

    Try the following code: ``` var tableName = await App.Database.TableNameLoad().Result;

    Entry.Text = tableName.PropertyA; ```

    App shows GetAwaiter error message.

    What is PropertyA? Is it about XAML Binding?

    ``` public Task> TableNameLoad() {

           var a = _database1.QueryAsync<TableName>("SELECT TableValue FROM [TableName];");
           return a;
        }
    

    ```

    Entry.Text = tableName.toString(); shows "system.thread ....." In this table, I want to keep one record that will be updated. I just can't get the value from this table.

    Wednesday, November 11, 2020 11:02 AM
  • User382871 posted

    What is PropertyA? Is it about XAML Binding? Because the 'TableNameLoad' method returns a value which is type of Task. But Entry.Text should be a string, you need pass a string type property of the 'TableName' class. The 'PropertyA' is a property of the 'TableName' class. public class TableName { ... public string PropertyA{ get; set; } }

    Wednesday, November 11, 2020 11:07 AM
  • User396669 posted

    I change it to string. Is "Entry2.Text = tableName.ToString();" a mistake ?

    Same error again.

    Wednesday, November 11, 2020 11:56 AM
  • User382871 posted

    What value do you want to set to the Entry.Text? The 'TableName' seems to be a class in your posted code.

    Wednesday, November 11, 2020 2:00 PM
  • User396669 posted

    In the tutorial on creating tables in sqlite, there was information that we create tables using classes. So I created a class where we have one column. On your advice, I changed this column to a string. It is used to record the current number that the user enters. Closes the application and writes this value to this table automatically. Opens the application and this value is to be loaded into the "Entry". Unfortunately, I don't know how to do this.

    This is how my table Looks

    public class TableName {

    [PrimaryKey, AutoIncrement, NotNull]
    public string TableValue{ get; set; }
    

    } Value is number, but it can be storage in string

    Wednesday, November 11, 2020 2:41 PM