System.Data.SQLite.SQLiteException: "SQL logic error no such column: Caesar"

SQLiteCommand cmd = conn.CreateCommand(); string sql_command = "DROP TABLE IF EXISTS person;" + "CREATE TABLE person(" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, " + "sex TEXT, " + "age INTEGER, " + "salary INTEGER, " + "position TEXT, " + "place INTEGER);"; for (int i = 0; i < 100; i++) { sql_command += "INSERT INTO person(name, sex, age, salary, position, place) " + "VALUES (" + workers_names[i] + ", " + people_gendar[i] + ", " + age[i] + ", " + salary[i] + ", " + people_position[i] + ", " + place[i] + "); "; } cmd.CommandText = sql_command; Console.WriteLine(sql_command); Console.WriteLine(cmd.ExecuteNonQuery()); try { Console.WriteLine(cmd.ExecuteNonQuery()); } catch (SQLiteException ex) { Console.WriteLine(ex.Message); } 
  • What's the question? What is not clear in the text of the error? - tym32167
  • gives this error when adding an array. Assigns all values ​​to the line normally. If you just take the values ​​from the arrays, it will record without problems - Artem Simonov
  • you show the contents of the result sql_command , which gives an error - tym32167
  • NEVER glue values ​​into SQL through + ! Use parameters to pass the inserted values: msdn.microsoft.com/en-us/library/… - PashaPash

1 answer 1

Single quotes around string field values ​​will correct the error from the question:

 sql_command += "INSERT INTO person(name, sex, age, salary, position, place) " + "VALUES ('" + workers_names[i] + "', '" + people_gendar[i] + "', " + age[i] + ", " + salary[i] + ", '" + people_position[i] + "', " + place[i] + "); "; 

Parameterize SQL queries - https://en.wikipedia.org/wiki/SQL_injection .