B
B
beduin012016-05-16 12:49:49
Database
beduin01, 2016-05-16 12:49:49

Why is the same copy of data inserted into the database?

I can't understand why the following code inserts the same copy of the data into the database.
This is how it looks.
The method accepts an array of data from the PG. Then it runs through it and inserts each element into SQLite. I even added the output of the elements. All different ones are output, but the same one is inserted stubbornly. Here is my code:

public void InsertData(List<UserData> PGuds)
        {
            Connection = new SQLiteConnection("Data Source=" + config.SQLLitePath + ";Version=3;");
            Connection.Open();
            
            SQLiteCommand insertSQL = new SQLiteCommand(@"INSERT INTO ""USERS"" (id, guid, username, userblob) VALUES (?,?,?,?)", (SQLiteConnection)Connection);
            try
            {
                Console.WriteLine(uds.Count);

                Console.WriteLine("iiiiiiiiiiiiiiiiiiiiii");
                foreach (UserData d in PGuds)
                {
                 Console.WriteLine("ooooooooooooo");
                 Console.WriteLine(d.Id);
                 Console.WriteLine(d.Guid);
                 Console.WriteLine(d.Name);
                insertSQL.Parameters.Add(new SQLiteParameter { Value = d.Id });
                insertSQL.Parameters.Add(new SQLiteParameter { Value = d.Guid });
                insertSQL.Parameters.Add(new SQLiteParameter { Value = d.Name });
                insertSQL.Parameters.Add(new SQLiteParameter { Value = d.UserBlob, DbType = DbType.Binary });

                insertSQL.ExecuteNonQuery();
                Console.WriteLine("Data Inserted in SQLLite");
                }

            }

            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);

            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2016-05-16
@beduin01

Not much in the subject, but most likely you need to place the line with the creation of the query ("SQLiteCommand insertSQL = new SQLiteCommand") in the loop too. Most likely, the Add method will not work when all the data has already been added.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question