将值插入 sqlite

Insert values into sqlite

我正在尝试将一些值插入到 c# 中的 sqlite 数据库中。所有值都是 label.text,但它不起作用,我认为出了点问题:

SQLiteConnection con = new SQLiteConnection("Data Source=Data/questions.sqlite;");

SQLiteCommand cmd = new SQLiteCommand("insert into finaltest(id,true,false,white,percent) values(3,'" + label1.Text + "','" + label2.Text + "','" + label3.Text + "','" + label4.Text + "')", con);

con.Open();
cmd.ExecuteNonQuery();         
con.Close();

我也尝试过使用 addwithvalue,但还是没用。

SQLiteConnection con = new SQLiteConnection("Data Source=Data/questions.sqlite;");

SQLiteCommand cmd = new SQLiteCommand("insert into finaltest(id,true,false,white,percent) values(3,@b,@c,@d,@e)", con);


cmd.Parameters.AddWithValue("@b", label2.Text);
cmd.Parameters.AddWithValue("@c", label3.Text);
cmd.Parameters.AddWithValue("@d", label4.Text);
cmd.Parameters.AddWithValue("@e", label5.Text);         
con.Open();
cmd.ExecuteNonQuery();

con.Close();

你可以试试这个: 1) Select 解决方案资源管理器中的 SQLite 数据库并将 'Copy to Output Directory' 的选项更改为 'Do not copy' 2)重建你的程序 3) 将您的 SQLite 数据库复制并粘贴到 bin\Debug\Data 目录 4)运行你的程序

现在应该提交更新。

其他资源: https://msdn.microsoft.com/en-us/library/ms246989.aspx

在解决方案资源管理器中单击数据库。

在属性 window 中将 "Copy to Output Directory" 值更改为 "Always copy",如图所示。

Attached Image

如果您认为它不适合您,只需关闭数据库实例 table 在主 Window 中打开,然后再次显示您的数据。因为当您显示数据时,如果先前的实例存在,那么它会关注那个 window 但没有更新。

Check Pic

对我有用。 :)