M
M
Maxim K2021-01-12 14:18:13
SQLite
Maxim K, 2021-01-12 14:18:13

How to update data in SQlite3 using C#?

Hello. I enter the given sqlite database in this way and everything works:

string connection = @"Data Source=c:\\sqlite\\taskdb.db;Version=3";
       SQLiteConnection sqlite_conn = new SQLiteConnection(connection);

           int i = Convert.ToInt32(isCompletedCheckBox.Checked);

            string stringQuery = "insert into task(task, doDate, Details, Done) values('" + this.titleTextBox.Text + "','" + this.doDatePicker.Text + "' ,'" + this.detailsTextBox.Text + "','" + i + "'  )";
            sqlite_conn.Open();//Open the SqliteConnection
            var SqliteCmd = new SQLiteCommand();//Initialize the SqliteCommand
                SqliteCmd = sqlite_conn.CreateCommand();//Create the SqliteCommand
                SqliteCmd.CommandText = stringQuery;//Assigning the query to CommandText
                SqliteCmd.ExecuteNonQuery();//Execute the SqliteCommand
                sqlite_conn.Close();//Close the SqliteConnection
            this.Close();


I try to update using this command, but accordingly it gives errors:

...................
 string stringQuery = "Update task SET (task, doDate, Details, Done) values('" + this.titleTextBox.Text + "','" + this.doDatePicker.Text + "' ,'" + this.detailsTextBox.Text + "','" + i + "'  )";
            sqlite_conn.Open();//Open the SqliteConnection
..............


I saw various solutions on the Internet, but they do not fit mine ((( How can I correct my request to update data in a row?
THANK YOU

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-01-12
@mkvmaks

UPDATE is spelled differently:

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question