【问题标题】:update data in sqlite [closed]更新sqlite中的数据[关闭]
【发布时间】:2013-12-14 08:13:13
【问题描述】:

我无法使用此代码更新我的数据,并且我在 sqlite 中的数据不会改变。

var path = ApplicationData.Current.LocalFolder.Path + @"\users.sqlite";
var db = new SQLite.SQLiteConnection(path);

var query = db.Table<User>().Where(c => c.ID == ID_countact_save).SingleOrDefault();
query.Fname = Fname_TB.Text;
query.Lname = Lname_TB.Text;
query.Phone = Phone_TB.Text;
query.Mobile = Mobile_TB.Text;
query.Address = Address_TB.Text;
query.Email = Email_TB.Text;

【问题讨论】:

    标签: c# sqlite windows-8 microsoft-metro


    【解决方案1】:

    设置字段不会自动更新数据库 您需要在 SQLiteConnection 对象中使用 Update 方法 就像

    db.Update(query);
    

    这是假设您的 ID 字段具有 [PrimaryKey] 属性 看这篇文章只是一个关于如何在事务中做事的例子。

    【讨论】:

      【解决方案2】:

      既然你只是想更新,你可以这样做:

      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = "Update User_table set Fname='"+Fname_TB.Text+"' where id='"+query.ID+"'";
      

      【讨论】:

        猜你喜欢
        • 2015-05-20
        • 1970-01-01
        • 2021-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多