E
E
estry2020-08-29 10:52:47
SQLite
estry, 2020-08-29 10:52:47

Is it possible to add a list with data at once in SQLite?

Hello. I need to add data to a SQLite table, I made a solution using iteration, but I would like to add a list en masse, is there a solution without iteration?

using (var db = new SQLiteConnection(conn))
{
  db.Open();
    SQLiteCommand selectCommand = new SQLiteCommand(db);

    try
    {
    foreach(var v in List)
    {
      selectCommand.CommandText = String.Format("INSERT OR REPLACE INTO test (re) VALUES ('{0}')", v.ToString());
      selectCommand.ExecuteScalar();
    }
        
    }
    catch(SQLiteException error)
    {
        //
    }
    db.Close();	
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-08-29
@freeExec

VALUEScan be listed separated by commas in one commandINSERT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question