How i can send data ,if it is possible ,from a program in c# to a postgresSql database.Thanks
Loading
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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Matthew HessPosted Jun 9, 2025, 2:52 PM
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)