Why is my Sqlite table doubling it's self?

My Sqlite table should have 50 rows. When I run the program for the first time, and go to check the table through firefox viewer, I see 50 rows (as it should be).

When I run the program for a second time and check the table, it's rows double - i,e it now has 100 rows. (This is the problem)

Ive had suggestions to use DELETE from, but I dont want to delete the table, as I want to see it in the firefox viewer after I run the program for debugging purposes.

 // We use these three SQLite objects:
          SQLiteConnection sqlite_conn;
          SQLiteCommand sqlite_cmd;

          // create a new database connection: 
          sqlite_conn = new SQLiteConnection(@"Data Source=database.db;Version=3;");

          // open the connection:
          sqlite_conn.Open();

          // create a new SQL command:
          sqlite_cmd = sqlite_conn.CreateCommand();

          // Let the SQLiteCommand object know our SQL-Query:
          sqlite_cmd.CommandText = "CREATE TABLE IF NOT EXISTS 'tab1' (Seq text, Field text, Desc text, Len text, Dec text, Typ text, Percnt text, Pop text, Alzero text, MaxLen text );";

          // Now lets execute the SQL                                                                                 
          sqlite_cmd.ExecuteNonQuery();

          // **** SQLITE TRANSFER SECTION 1 - transfer values from list to table *****

          sqlite_cmd.CommandText = "INSERT INTO tab1 (Seq, Field, Desc, Len, Dec, Typ, Percnt, Pop, Alzero, MaxLen) VALUES (@p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10)";
          sqlite_cmd.Parameters.AddWithValue("@p1", 6);  // dummy initial values 
          sqlite_cmd.Parameters.AddWithValue("@p2", 878); 
          sqlite_cmd.Parameters.AddWithValue("@p3", 56);
          sqlite_cmd.Parameters.AddWithValue("@p4", 6);
          sqlite_cmd.Parameters.AddWithValue("@p5", 546);
          sqlite_cmd.Parameters.AddWithValue("@p6", 565);
          sqlite_cmd.Parameters.AddWithValue("@p7", 568);
          sqlite_cmd.Parameters.AddWithValue("@p8", 526);
          sqlite_cmd.Parameters.AddWithValue("@p9", 586);
          sqlite_cmd.Parameters.AddWithValue("@p10", 526);


          for (int i = 0; i < NumListValues; i += 10) // Filling SQlite table rows and columns with values from our list 
          {

              sqlite_cmd.Parameters.AddWithValue("@p1", list[i]);
              sqlite_cmd.Parameters.AddWithValue("@p2", list[i+1]);
              sqlite_cmd.Parameters.AddWithValue("@p3", list[i+2]);
              sqlite_cmd.Parameters.AddWithValue("@p4", list[i+3]);
              sqlite_cmd.Parameters.AddWithValue("@p5", list[i+4]);
              if (i > 490)
                  break; 
              sqlite_cmd.Parameters.AddWithValue("@p6", list[i+5]);
              sqlite_cmd.Parameters.AddWithValue("@p7", list[i+6]);
              sqlite_cmd.Parameters.AddWithValue("@p8", list[i+7]);
              sqlite_cmd.Parameters.AddWithValue("@p9", list[i+8]);
              sqlite_cmd.Parameters.AddWithValue("@p10", list[i+9]);
              sqlite_cmd.ExecuteNonQuery();

          }
Jon Skeet
people
quotationmark

When I run the program for a second time and check the table, it's rows double - i,e it now has 100 rows.

Well yes, it would. You've said to create the table if it doesn't exist, and then you're inserting a bunch of data, without removing what was already there.

It won't actually double each time - it'll just add NumListValues / 10 rows every time you run it, because that's what you've said you want to do.

If you want to delete any existing rows from the table before you start inserting (i.e. at the start of the run rather than at the end) then you'll need to do so explicitly. You could either use TRUNCATE TABLE or DELETE FROM ....

people

See more on this question at Stackoverflow