I am trying to get data from Postgres table with a help of stored procedure and fill a Winforms DataGrid with it.
This is the stored procedure:
CREATE OR REPLACE PROCEDURE public.get_list()
LANGUAGE sql
BEGIN ATOMIC
SELECT field1,
field2,
field3
FROM some_table;
END;
Here's my C# code:
DataTable dtt = new DataTable();
string ConString = "Server=x.xxx.xx.xxx;Port=5432;User Id=xxx;Password=xxx;Database=xxx;";
NpgsqlConnection connection = new NpgsqlConnection(ConString);
connection.Open();
NpgsqlCommand cmd = new NpgsqlCommand("CALL public.get_list()");
try
{
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
using (var dataReader = cmd.ExecuteReader())
{
if (dataReader.HasRows)
{
GridView.Visible = true;
dtt.Load(dataReader);
GridView.DataSource = dtt;
GridView.Update();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
After executing this code, the DataReader returns 0 rows.
The stored procedure returns nothing: fiddle
CALL public.get_list();
CALL
What am I doing wrong?
Maybe the analog of a stored procedure in other RDBMSs (for example in SQL Server) in Postgres is a function?
select * from public.get_list())