2017-03-15 12 views
0

當我嘗試更新Windows應用程序中的列時,出現錯誤,我正在使用此查詢。
string qu = "UPDATE Registration_class SET numOfSeat = 300"; await MainPage.con.UpdateAsync(qu);如何在通用Windows應用程序中更新Sqlite中的列

Here is the Error Screenshot

如果您需要任何其他信息,請告訴我。 Thankyou。

+0

您嘗試更新它沒有主鍵的表。可以在沒有主鍵的情況下更新數據(例如使用rownum)。但是你可能只是忽略了創建pk的部分,你應該考慮它。如果沒有這個值,數據庫引擎無法區分特定行,儘管事實上您嘗試一次更新所有行。 更多:[link](http://stackoverflow.com/questions/840162/should-each-and-every-table-have-a-primary-key) – soshman

+0

'public class Registration_class { public string name {get ;組; } public string password {get;組; } public int numOfSeat {get;組; }這是表格,我在這裏做了錯誤,可以告訴我如何解決它。 –

回答

1

我不確定你正在使用哪個sqlite版本。然後,如果只是根據錯誤信息,您應該爲您的表指定PrimaryKey

例如,像下面這樣:

public class Registration_class 
{ 
    [PrimaryKey, AutoIncrement] 
    public int Id {get;set;} 
    public string name { get; set; } 
    public int numOfSeat { get; set; } 
    public string password { get; set; } 
} 

然後,我會在你的代碼指出另一種錯誤的地方。如果要直接執行sql語句,則應該使用db.Execute("UPDATE Registration_class SET numOfSeat = 300");方法,而不是Update方法。

我的代碼示例是基於Diederik的博客:Using SQLite on the Universal Windows Platform

相關問題