SQLiteDataAdapter更新未更新

kr98yfug  于 2023-05-07  发布在  SQLite
关注(0)|答案(1)|浏览(172)
private void potrdi_Click(object sender, EventArgs e)
    {    
        string id = idFilma.Text;
        double nova = double.Parse(novaOcena.Text);

        DataSet ds = new DataSet();
        string povNiz = @"Data Source=C:\Users\filmi.sqlite;Version=3";
        SQLiteConnection povezava = new SQLiteConnection(povNiz);

        SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT id, naslov, ocena FROM filmi WHERE id =" + id, povezava);
        dataAdapter.Fill(ds);

        SQLiteCommand cmd = new SQLiteCommand("UPDATE filmi SET ocena = " + nova + " WHERE id = " + id, povezava);

        SQLiteCommandBuilder builder = new SQLiteCommandBuilder(dataAdapter);
        dataAdapter.UpdateCommand = builder.GetUpdateCommand(true);

        dataAdapter.UpdateCommand = cmd;
        dataAdapter.Update(ds);

        prikazPodatkov2.DataSource = ds.Tables[0];
    }

我一直在Windows窗体应用程序工作。
选择后的更新不起作用。我尝试了很多方法,但没有一种对我有效。我用的是SQLite数据库。更新后,我得到的结果与更新前的选择相同。
请帮帮忙,我已经试着修了三天了,快把我弄疯了。

ni65a41a

ni65a41a1#

dataAdapter.Update(ds);之前使用dataAdapter.AcceptChangesDuringUpdate = true;

...
SQLiteCommandBuilder builder = new SQLiteCommandBuilder(dataAdapter);
dataAdapter.UpdateCommand = builder.GetUpdateCommand(true);

dataAdapter.UpdateCommand = cmd;
dataAdapter.AcceptChangesDuringUpdate = true;
dataAdapter.Update(ds);
...

相关问题