title: How to execute INSERT INTO in SQLite with ODBC in c#
body: <p>The function of application is to select some values from one database (PSQL) and insert it into another database (SQLite). But code below does not work, it stops at executing line and shows no error, but last forever (also if I use SELECT TOP 1 ...). </p>
  
  <pre><code>//... odbc conection to DSN, this works fine
  odbc.dbsqlite.Open();
  odbc.dbpsql.Open();
  
  //sql command
  OdbcCommand comsqlite = odbc.dbsqlite.CreateCommand();
  OdbcCommand compsql = odbc.dbpsql.CreateCommand();
  
  //SQL for select ... this works
  compsql.CommandText = "SELECT DISTINCT ..." 
  
  compsql.Parameters.AddWithValue("@sifra", "VP");
  ...
  
  // from here is problem
  try
  {
      OdbcDataReader dbReader = compsql.ExecuteReader();
      OdbcTransaction transaction = odbc.dbsqlite.BeginTransaction();
  
      var ordinal = new
      {
         cenik = dbReader.GetOrdinal("sifra"),
         ident = dbReader.GetOrdinal("ident"),
         klasi = dbReader.GetOrdinal("klasi"),
         cena  = dbReader.GetOrdinal("cena"),
         eankoda = dbReader.GetOrdinal("eankoda"),
      };
  
      int count = 0;
  
      while (dbReader.Read())
      {
         //here single variable gets results 
         var cena = Convert.ToDouble(dbReader.GetDouble(ordinal.cena));
         var ident = Convert.ToString(dbReader.GetString(ordinal.ident));
         var cenik = Convert.ToString(dbReader.GetString(ordinal.cenik));
         var klasi = Convert.ToString(dbReader.GetString(ordinal.klasi));
         var eanko = Convert.ToString(dbReader.GetString(ordinal.eankoda));
  
         comsqlite.CommandText = "INSERT INTO ARTIKLI (KLASI, CENA, BARKODA, CENIK, IDENT) VALUES (?,?,?,?,?);";
  
         comsqlite.Parameters.AddWithValue("@KLASI", klasi);
         comsqlite.Parameters.AddWithValue("@CENA", cena);
         comsqlite.Parameters.AddWithValue("@BARKODA", eanko);
         comsqlite.Parameters.AddWithValue("@CENIK", cenik);
         comsqlite.Parameters.AddWithValue("@IDENT", ident);
  
          if (count % 1000 == 0)
          {
             transaction.Commit();
             transaction.Dispose();
             **comsqlite.ExecuteNonQuery(); //here it stops and give no results**
             transaction = odbc.dbsqlite.BeginTransaction();
  
           }
           count++;
  
           }
  
           comsqlite.Dispose();
           odbc.dbsqlite.Close();
  
           transaction.Commit();
           transaction.Dispose();
  
           dbReader.Close();
           compsql.Dispose();
           odbc.dbpsql.Close();
  
          }
          catch (Exception e)
          {
              Console.WriteLine("Error: "+ e);
              throw;
          }
  </code></pre>