<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89" -->

---
title: CRUD operations on PostgreSQL using C# and Npgsql
description: A step-by-step walkthrough shows how to perform CRUD operations against PostgreSQL using C# and the Npgsql NuGet package. It covers opening a connection,...
canonical: https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: CRUD operations on PostgreSQL using C# and Npgsql | daily.dev
og:description: A step-by-step walkthrough shows how to perform CRUD operations against PostgreSQL using C# and the Npgsql NuGet package. It covers opening a connection,...
og:url: https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89
og:image: https://api.daily.dev/og/posts/p0pgqfi89.png
og:image:alt: CRUD operations on PostgreSQL using C# and Npgsql
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CRUD operations on PostgreSQL using C# and Npgsql

**[Code4IT](https://daily.dev/sources/code4it)** · 9 min read · 0 upvotes · 0 comments

## Summary

A step-by-step walkthrough shows how to perform CRUD operations against PostgreSQL using C# and the Npgsql NuGet package. It covers opening a connection, composing a connection string, and implementing Create, Read, Update, and Delete methods using NpgsqlCommand, parameterized queries (to avoid SQL injection), and NpgsqlDataReader. It also explains the difference between ExecuteNonQueryAsync and ExecuteReaderAsync, shows how to create a table programmatically, and demonstrates two ways to check the PostgreSQL version from C# code.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/postgres-crud-operations-npgsql>

## Questions this post answers

### How do I perform CRUD operations against PostgreSQL in C# using Npgsql?

Use NpgsqlConnection to open a connection, then NpgsqlCommand with parameterized SQL for insert, select, update, and delete statements. Use ExecuteNonQueryAsync for INSERT, UPDATE, and DELETE since they only return affected row counts, and ExecuteReaderAsync with NpgsqlDataReader for SELECT queries that return data, reading each column by name and casting to the expected type.

_Developers wiring up a .NET data layer can find Npgsql CRUD patterns and comparisons on daily.dev._

### What is the difference between ExecuteNonQueryAsync and ExecuteReaderAsync in Npgsql?

ExecuteNonQueryAsync executes commands like INSERT, UPDATE, and DELETE that only return the number of rows affected, not actual data. ExecuteReaderAsync is used for SELECT queries and returns an NpgsqlDataReader, a read-only stream of rows that can be iterated asynchronously to fetch column values from the result set.

_daily.dev surfaces practical comparisons like this for developers deciding between data access approaches in .NET._

## Similar posts on daily.dev

- [How to Work With Dapper in .Net](https://daily.dev/posts/how-to-work-with-dapper-in-net-yzgrlyllb) · freeCodeCamp · 17 upvotes · 0 comments
- [Meet the New dotConnect for PostgreSQL Release](https://daily.dev/posts/meet-the-new-dotconnect-for-postgresql-release-y2g3qlctk) · PostgreSQL · 1 upvotes · 0 comments
- [Building CRUD API with Dapper and Dapper Plus in ASP.NET Core](https://daily.dev/posts/building-crud-api-with-dapper-and-dapper-plus-in-asp-net-core-pzojrv4vq) · We Are .NET · 0 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#sql](https://daily.dev/tags/sql), [#postgresql](https://daily.dev/tags/postgresql), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"CRUD operations on PostgreSQL using C# and Npgsql","url":"https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89"},"datePublished":"2026-10-04T13:05:30.753Z","dateModified":"2026-10-04T13:11:54.186Z","description":"A step-by-step walkthrough shows how to perform CRUD operations against PostgreSQL using C# and the Npgsql NuGet package. It covers opening a connection,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/21588b2c233de432106a7c94e84f564b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/21588b2c233de432106a7c94e84f564b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,sql,postgresql,c#","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"CRUD operations on PostgreSQL using C# and Npgsql"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/crud-operations-on-postgresql-using-c-and-npgsql-p0pgqfi89#faq","mainEntity":[{"@type":"Question","name":"How do I perform CRUD operations against PostgreSQL in C# using Npgsql?","acceptedAnswer":{"@type":"Answer","text":"Use NpgsqlConnection to open a connection, then NpgsqlCommand with parameterized SQL for insert, select, update, and delete statements. Use ExecuteNonQueryAsync for INSERT, UPDATE, and DELETE since they only return affected row counts, and ExecuteReaderAsync with NpgsqlDataReader for SELECT queries that return data, reading each column by name and casting to the expected type. Developers wiring up a .NET data layer can find Npgsql CRUD patterns and comparisons on daily.dev."}},{"@type":"Question","name":"What is the difference between ExecuteNonQueryAsync and ExecuteReaderAsync in Npgsql?","acceptedAnswer":{"@type":"Answer","text":"ExecuteNonQueryAsync executes commands like INSERT, UPDATE, and DELETE that only return the number of rows affected, not actual data. ExecuteReaderAsync is used for SELECT queries and returns an NpgsqlDataReader, a read-only stream of rows that can be iterated asynchronously to fetch column values from the result set. daily.dev surfaces practical comparisons like this for developers deciding between data access approaches in .NET."}}]}
```

