I have a table named profit model:
我想激活不同的利润模型,表格中的数据将会更新。
现在我正在使用UpdateAsync,但它不起作用......我怎样才能实现这一点?
async void Active_Clicked(object sender, System.EventArgs e)
{
var profitmodel = (sender as Button).CommandParameter as ProfitModel;
await conn.CreateTableAsync<ProfitModelInUsed>();
//System.Diagnostics.Debug.WriteLine(product.ProductName);
var profitmodelInUsed = new ProfitModelInUsed
{
ProfitModel_ID = profitmodel.ProfitModel_ID,
ProfitModel_Name = profitmodel.ProfitModel_Name,
ExchangeRate = profitmodel.ExchangeRate,
Profit = profitmodel.Profit
};
await conn.UpdateAsync(profitmodelInUsed);
await DisplayAlert("This ProfitModel is Applied", profitmodelInUsed.ProfitModel_Name, "OK");
}
我不希望在此表中有多行。
答案 0 :(得分:0)
将PrimaryKey
应用于ProfitModel_ID
模型中的ProfitModelInUsed
媒体资源:
public class ProfitModelInUsed
{
[PrimaryKey]
public string ProfitModel_ID { get; set; }
// ~~~ other properties
}
使用ProfitModel_ID
:
const
属性
profitmodelInUsed.ProfitModel_ID = "InUseProfitModel"
await conn.UpdateAsync(profitmodelInUsed);
通过以下方式回复:
var profitmodelinuse = conn.FindAsync<ProfitModelInUsed>("InUseProfitModel");