我是SQLite的初学者。现在我正试图在示例northwind数据库中插入新记录。我的C#代码如下:C#SQlite INSERT INTO不起作用
SQLiteConnection myConnection = new SQLiteConnection();
myConnection.ConnectionString = @"Data Source=|DataDirectory|\northwindEF.db";
using (myConnection)
{
SQLiteCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "INSERT INTO Categories(CategoryID,CategoryName,Description) VALUES(11,'Bakery','Baked goods such as bread and cakes')";
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
当我运行这个程序,我没有得到任何错误。但我的新纪录没有插入表格。我的代码有什么问题。请帮帮我。
我不知道,但如果类别ID是主键,改变你的查询是这样的:“INSERT INTO类别(类别名称,描述)VALUES(‘面包’,‘烘焙食品,如面包,蛋糕’)” – 2013-03-20 22:13:02
CategoryID是主键。正如你所说,我改变了我的查询,但问题仍然存在。 :-( – 2013-03-20 22:23:46
SQLiteCommand可能需要用分号终止CommandText属性 – pixelbadger 2013-03-20 22:24:30