// create a SQL command NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM users WHERE id = @id", connection); // add a parameter to the command command.Parameters.AddWithValue("id", 1); // execute the command and read the results NpgsqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { // do something with the data }
using (NpgsqlCommand command = new NpgsqlCommand()) { command.CommandText = "INSERT INTO users (name, email) VALUES (@name, @email)"; command.Parameters.AddWithValue("name", "John Doe"); command.Parameters.AddWithValue("email", "[email protected]"); command.Connection = connection; int rowsAffected = command.ExecuteNonQuery(); }This example shows how to create an INSERT SQL command with parameters and execute it against a PostgreSQL database using NpgsqlCommand. It also shows how to get the number of affected rows using `ExecuteNonQuery()` method. The package library for Npgsql is `Npgsql.EntityFrameworkCore.PostgreSQL` which is used to integrate Npgsql with Entity Framework Core.