title: How to get "no rows" error when execute raw SQL with NPGSQL?
body: <p>I'm new to C# so I apologize if this is an obvious question but I can't seem to find an answer to it. I'm writing a client application that takes a raw SQL command and passes it directly to the database.  I don't know if it will be an <code>select</code>, <code>update</code>, <code>insert</code>, or <code>delete</code>.  If it's a <code>select</code>, I want to get the results into a <code>DataTable</code>.  If it's anything else, I want to know if it was successful or if there was an error in execution (for example: no rows were affected).</p>
  
  <p>I am current doing the below code before I found out it doesn't return any errors for <code>update</code> or <code>delete</code> affects no rows.  I formatted the code but tried to leave enough to understand what I am trying to do.  Since this is my first question on here, if you have any tips on how better to contextualise my questions, please share.</p>
  
  <pre><code>class Client
  {
      static void Main(string[] args)
      {
          Config.LoadConfig();
          Db.Init();
  
          var testQuery1 = "select * from test where 1=1";
          var testQuery2 = "update test set value='value3' where name = 'name3'";
          var testQuery3 = "insert into test (id, name, value, date) values (4,'name4','value4',current_timestamp)";
  
          Db.Query(testQuery1);
          Db.PrintResults();
  
          Db.Query(testQuery2);
          Db.PrintResults();
  
          Db.Query(testQuery3);
          Db.PrintResults();
      }
  }
  
  /// &lt;summary&gt;
  /// Universal database class.
  /// &lt;/summary&gt;
  public static partial class Db
  {
      private static IUniversalDatabase _dbUniConn;
  
      /* Database Results */
      public static string ErrorCode { get; private set; }
      public static string ErrorMessage { get; private set; }
      public static int RowCount { get; private set; }
      public static double ExecutionSeconds { get; private set; }
      public static DataTable Data { get; private set; } = new DataTable();
  
      public static void Init(string connString, Type dbType)
      {
          try
          {
              _connString = connString;
              _connType = dbType;
  
              switch (_connType)
              {
                  case Db.Type.PostgreSQL:
                      _dbUniConn = new PostgresDatabase(_connString);
                      break;
                  ...
              }
          }
      }
  
      public static void Open()
      { ...  _dbUniConn.Open(); ...  }
  
      public static void Close()
      { ...  _dbUniConn.Close(); ...  }
  
      public static void Query(string cmdString)
      {
          var start = DateTime.Now;
  
          Open();
  
          /* Reset Data */
          Data.Reset();
          RowCount = 0;
          ErrorMessage = "";
          ErrorCode = "";
  
          /* Execute Query */
          _dbUniConn.Query(cmdString);
  
          /* Execution Time */
          ExecutionSeconds = (DateTime.Now - start).TotalSeconds;
          Debug.Write("Database:    Execution Time: " + ExecutionSeconds.ToString() + " seconds", Debug.TraceLevel.Info);
  
          /* RowCount and Error Message */
          RowCount = Data.Rows.Count;
          Debug.Write("Database:    Returning " + RowCount.ToString() + " rows", Debug.TraceLevel.Info);
          Debug.Write("Database:    Error (" + ErrorCode + "): " + ErrorMessage, Debug.TraceLevel.Info);
  
          Close();
      }
  
      public class PostgresDatabase : IUniversalDatabase
      {
          private NpgsqlConnection _dbConn;
  
          public PostgresDatabase(string connString)
          { _dbConn = new NpgsqlConnection(connString); }
  
          public void Open()
          { _dbConn.Open(); }
  
          public void Close()
          { _dbConn.Close(); }
  
          public void Dispose()
          { _dbConn.Dispose(); }
  
          public void Query(string cmdString)
          {
              NpgsqlCommand cmd = new NpgsqlCommand(cmdString, _dbConn);
              NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);
              cmd.CommandType = System.Data.CommandType.Text;
  
              try
              {
                  da.Fill(Data);
              }
              catch (Exception e)
              {
                  MatchCollection configVar = Regex.Matches(e.Message.ToString(), @"^(?&lt;code&gt;.*?): (?&lt;msg&gt;.*?)$");
                  foreach (Match match in configVar)
                  {
                      ErrorCode = match.Groups["code"].Value.ToString();
                      ErrorMessage = match.Groups["msg"].Value.ToString();
                  }
              }
              da.Dispose();
              cmd.Dispose();
          }
      }
  }
  </code></pre>