如何通过获取每一行的 id 在数据库中使用此函数更新每一行?

How to update every row using this function in database by getting the id of every row?

如何使用此函数通过获取每一行的 ID 来更新 sqlite-net-pcl 数据库中的每一行,即使我稍后创建了新行。为了分解它,我需要 table 中每个现有行的 ID,并且我需要将每个 ID 放入此函数中并更新 table.

private void refreshData()
{
    using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
    {
        var **buyAmount** = conn.Get<userInput>(**id**).buyAmount;
        var **symbol** = conn.Get<userInput>(**id**).Pair.ToString();

        HttpClient client = new HttpClient();
        var response = await client.GetStringAsync("https://api.binance.com/api/v3/ticker/price?symbol=" + **symbol**);
        var cryptoconverted = JsonConvert.DeserializeObject<Crypto>(response);
        var currentPriceDouble = double.Parse(cryptoconverted.price);
        var finalAnswer = double.Parse(cryptoconverted.price) * double.Parse(**buyAmount**);
        conn.Execute("UPDATE userInput SET worth = " + finalAnswer + " where Id= " + **id**);
    };
}

userInput.cs

using System;
using SQLite;

namespace CryptoProject.Classes
{
    public class userInput
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
        public string Pair { get; set; }
        public string buyPrice { get; set; }
        public string buyAmount { get; set; }
        public double spent{ get; set; }
        public double worth{ get; set; }

        public userInput()
        {
        }

        public static implicit operator string(userInput v)
        {
            throw new NotImplementedException();
        }
    }
}


如果您想遍历 table 中的每一行并更新它,则查询所有行的列表并使用 foreach

遍历它们
// get all rows from your db
var stocks = conn.Table<userInput>().ToList();

// loop through each row
forech(var s in stocks)
{
  // do whatever logic you need here
  ...

  // then update the object properties
  s.worth = ...
  ...

  // then save
  conn.Update(s);
}