

That takes a bit more code but is clearer. ToList() should be sufficient personally I do this with an extra foreach and an intermediate list, think things-to-remove-after-foreach-is-done. I don't like your OfType().ToArray() trick allowing you to remove items while still enumerating the checked items. code looks much nicer if you apply a using statement for objects that need being disposed of when done, such as your connection. there is no need to open and close the connection for each iteration in a foreach loop

Finally I have several comments on your coding these probably won't affect the program behavior but improvement is welcome: If adding such observability isn't sufficient, now is the time to start using the debugger.Ĩ. That way you should see only a few numbers, and they should all match when they don't, you get a first hint as to what is wrong.ħ. and NOT display every single item you try to delete. accumulate the return values of ExecuteNonQuery while attempting to delete, and display that number. Pros: When the other data entities are Important and you just want to delete only tables from the schema, this approach will really helpful to you. accumulate the return values of ExecuteNonQuery while adding, and display that SELECT DROP TABLE IF EXISTS ' tablename ' CASCADE from pgtables WHERE schemaname public As you can see, By the use of subquery, We can remove the entire tables from the schema. count and display the number of checked items

As Garth already mentioned, you are ignoring the return value of ExecuteNonQuery. It would help if you were to show real code.Ħ. What purpose would that serve? and how would that support your statment about deletion in a second run, as there is no code shown that only tries to delete.ĥ. You show a single method, which first adds items to the database and then removes the same items. It would help if you described an actual scenario, such as: initial list contains A,B,C,D with B and C checked, then I. Especially how that differs between your first and second run of the program.ģ. It is unclear which items get shown, and which gets checked. You work with checked items, what are those? and while removing, you remove the items form the display. To drop/delete or remove in psql, we are. In PostgreSQL, we can drop the table in two ways: Dropping a table from psql Drop table in pgAdmin Dropping a table from psql. And the drop table is the keyword which is used to drop a table. You display a number of items, please explain what they are. Here the table name parameter is used to define the name of the table, which we will delete from the database. Your formulation of the problem is quite unclear.ġ. Var sql2 = " DELETE FROM zadania WHERE cmd2 = new NpgsqlCommand(sql2, con) Ĭ( " zaadanie", item2) Var cs = " Host=localhost Username=postgres Password=root Database=Dziennik" Var sql = " INSERT INTO zadaniaarchiwalne(zadanie_archiwalne) cmd = new NpgsqlCommand(sql, con2) Ĭmd.Parameters.AddWithValue( " zadanie", item) įoreach ( var item2 in ().ToArray()) Dodanie do archiwalnych zadań var cs2 = " Host=localhost Username=postgres Password=root Database=Dziennik" Copy Code private void button1_Click( object sender, EventArgs e) // Aktualizujįoreach ( var item in checkedListBox1.CheckedItems)
