How i can send data ,if it is possible ,from a program in c# to a postgresSql database.Thanks
C# and pgadmin
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
How i can send data ,if it is possible ,from a program in c# to a postgresSql database.Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Matthew Hess114 reputationPosted Jun 9, 2025, 10:52 AM EDT
To communicate with any SQL database from C#, the easiest and recommended approach is to use the ADODB driver for the target database. This allows you to write C# code that is, for the most part, target datase agnostic. In other words, you can use the same (mostly) code to talk to MSSQL, MySQL, Maria, Postgres etc... In the case of PostgresSQL, the driver is called Npgsql. It's open source and you can read about how to use it here: https://www.npgsql.org/
At a high level, ADODB programming generally follows this basic flow:
1. Create and Open a Connection object using a Connection String
2. Create a Command object using your open Connection and some SQL
3. Set any Parameters on your Command object (if it is happens to use Parameters.
4. Execute the Command. If it is a query type command that returns a result set, use a DataReader object to iterate and process the results.
There are, of course, nuances and variations and there are tons of examples on the web. Good luck!
-Matthew (Youtube: @CSharpArtisan)