2017-09-25 8 views
1

I have a table named profit model:どのようにデータベース内の行を1つに制限できますか?

私は別の利益モデルを有効にしたいと考えており、テーブルのデータが更新されます。

今、私は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

はあなたProfitModelInUsedモデル内PrimaryKeyあなたProfitModel_IDプロパティに適用します。

public class ProfitModelInUsed 
{ 
    [PrimaryKey] 
    public string ProfitModel_ID { get; set; } 
    // ~~~ other properties 
} 

と使用ProfitModel_IDプロパティを設定const

profitmodelInUsed.ProfitModel_ID = "InUseProfitModel" 
await conn.UpdateAsync(profitmodelInUsed); 

経由でRetrive:

var profitmodelinuse = conn.FindAsync<ProfitModelInUsed>("InUseProfitModel"); 
+0

感謝Bro !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!あなたの助言は役に立つ!!!!!!!!!! –

関連する問題