Hey, currently working on a DB project for the first time with PostgreSQL and for some reason this insert operation inserts the first entry in the list for the length of the list into the DB resulting in mass duplicate entries of just the first entry of the list.
var sql = @"INSERT INTO outstanding(name) VALUES(@name)"; using var cmd = new NpgsqlCommand(sql, con); foreach (var item in outstanding) { cmd.Parameters.AddWithValue("name",item); cmd.Prepare(); cmd.ExecuteNonQuery(); }
var sql = @"INSERT INTO outstanding(name) VALUES(@name)"; using var cmd = new NpgsqlCommand(sql, con); foreach (var item in outstanding) { cmd.Parameters.AddWithValue("name",item); cmd.Prepare(); cmd.ExecuteNonQuery(); }
What did I miss? TYIA
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
C
C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.