2013-07-07 39 views
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); 
      } 
     } 

回答

1

如果設置該屬性Copy To The Output DirectoryCopy Always,每次你開始在VS調試會話,從項目文件夾中的數據庫的副本複製到輸出目錄(通常是BIN \ DEBUG)。您只需要將該屬性更改爲Copy If Newer

+0

很多感謝的人! –