0
我有一個命令INSERT的問題。 我編譯的應用程序,這個工程,但該行沒有插入數據庫(沒有引發任何錯誤)。數據庫包含在項目中,並具有「始終複製」屬性。 我正在開發一個WPF和C#項目,但對於連接和查詢,我使用C#。C#SQLite插入不起作用
謝謝!
public SQLiteConnection conexion;
SQLiteCommand cmd;
public MainWindow()
{
InitializeComponent();
Conectar();
}
public void Conectar()
{
try
{
//Connection
conexion = new SQLiteConnection("Data Source=eldelbar.s3db;Version=3;New=True;Compress=True;");
conexion.Open();
//Insert query
string insercion = "insert into cerveza (nombre,precio) values('amstel', 1.3);";
cmd = new SQLiteCommand(insercion, conexion);
int cantidad = cmd.ExecuteNonQuery();
if (cantidad < 1)
MessageBox.Show("No se ha podido insertar");
cmd.Dispose();
conexion.Close();
}
catch (Exception e)
{
MessageBox.Show("Error2!" + e.Message);
}
}
很多感謝的人! –