title: C# and PostgreSQL
body: <p>Can anyone show me a working example of using a cursor returned from PLSQL to C# code?</p>
  
  <p>I found many examples showing how to fill a <code>dataSet</code> with returned data, but I cannot find how to use that cursor with a <code>DataReader</code>, so as a result I have <code>{unnamed portal}</code>.</p>
  
  <pre><code>NpgsqlTransaction tr = (NpgsqlTransaction) Connection.BeginTransaction();
  NpgsqlCommand cursCmd = new NpgsqlCommand("someStoredProcedure(:inRadius)", (NpgsqlConnection) Connection);
  cursCmd.Transaction = tr;
  NpgsqlParameter rf = new NpgsqlParameter("ref", NpgsqlTypes.NpgsqlDbType.Refcursor);
  rf.Direction = ParameterDirection.InputOutput;
  cursCmd.Parameters.Add(rf);
  </code></pre>
  
  <p>I have to add this to use <code>NpgsqlDataReader myReader;</code> correctly:</p>
  
  <pre><code>tr.Commit();
  </code></pre>
  
  <p>When I wrote <code>fetch</code> after the sql command, it works but it is not suitable.</p>