0

I have a problem with the command INSERT. I compile the application and this works but the row isn't inserted in the database (no throws any error). The database is included in the project and has the property "Copy always". I'm developing a project with WPF and C#, but for the connection and querys, i use C#.

Thanks!

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);
            }
        }
0

1 Answer 1

1

If you set the property Copy To The Output Directory to Copy Always, everytime you start a debug session in VS, a copy of the database from the project folder is copied to the output directory (usually BIN\DEBUG). You need simply to change that property to Copy If Newer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.