Answers for "perform a select in npgsql"

0

perform a select in npgsql

using System;
   using Npgsql;
 
   class Sample
   {
       static void Main(string[] args)
       {
          // Connect to a PostgreSQL database
          NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=postgres; " + 
             "Password=pwd;Database=postgres;");
          conn.Open();
 
          // Define a query returning a single row result set
          NpgsqlCommand command = new NpgsqlCommand("SELECT COUNT(*) FROM cities", conn);
 
          // Execute the query and obtain the value of the first column of the first row
          Int64 count = (Int64)command.ExecuteScalar();
 
         Console.Write("{0}\n", count);
         conn.Close();
     }
   }
Posted by: Guest on July-10-2021

Browse Popular Code Answers by Language