Returning a recordset and filling datatable in a .NET applicatio n

From: Jonas Wouters <Jonas(at)vanroey(dot)be>
To: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>, "'pgsql-cygwin(at)postgresql(dot)org'" <pgsql-cygwin(at)postgresql(dot)org>
Subject: Returning a recordset and filling datatable in a .NET applicatio n
Date: 2002-10-31 15:33:08
Message-ID: A6FF006530424A42AA2924E5CCBE35293B9B20@msx.vanroey.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-cygwin pgsql-sql

Hi,

I have a problem with using .NET and PostgreSQL. In a previous thread called
"" I noticed that it is possible to use and create functions that return
tuples or RecordSets. I now want to use them in .NET.

I followed the instructions which are available at :
http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html these
work in the standard psql client :

I created the function using the following :

CREATE FUNCTION public.p0012_fetch_supplier(varchar, varchar, refcursor)
RETURNS refcursor AS '
BEGIN
OPEN $3 FOR SELECT * FROM "SUPP_T" WHERE "CODE" = $1 AND "DSRCODE" =
$2;
RETURN $3;
END;
' LANGUAGE 'plpgsql' VOLATILE;

Then I did these in psql :

SBA=# BEGIN;
BEGIN
SBA=# SELECT p0012_fetch_supplier('1','1','funccursor');
p0012_fetch_supplier
----------------------
funccursor
(1 row)

SBA=# FETCH ALL IN funccursor;
DSRCODE | CODE
1 | 1
(1 row)

SBA=# COMMIT;
COMMIT

The results tell me that the function works. (whoohoo)

But when I do the same thing in a .Net application, I get an empty DataTable
(row count = 0)

This is what I do in .Net 5and I do know that most of you people dislike
.NET and actually .. that is not the issue for me :), I just want this to
work because we are going to need this for our application)

Dim CN As New Microsoft.Data.Odbc.OdbcConnection("DSN=PostgreSQL30")
Dim CM As New Microsoft.Data.Odbc.OdbcCommand("BEGIN; SELECT
p0012_fetch_supplier('1','1','funccursor'); FETCH ALL IN
funccursor; COMMIT;", CN)
Dim DA As New Microsoft.Data.Odbc.OdbcDataAdapter(CM)
Dim DT As New DataTable()
Try

CM.CommandType = CommandType.Text
DA.SelectCommand.Connection.Open()
DA.Fill(DT)
DA.SelectCommand.Connection.Close()
Catch ex As Microsoft.Data.Odbc.OdbcException
Debug.WriteLine(ex.Message)
Debug.WriteLine(ex.Source)
Debug.WriteLine(ex.HelpLink)
Finally
CN.Close()

It does not raise an exception so there are no real 'errors'; it just does
not give 'data' to the ADO.NET container.

If I am asking this in the wrong mailinglist, then please point me in the
right direction. I don't think that I will get a answer at Microsoft.com so
that is why I ask it here ..

Thx in advance
Jonas

Responses

Browse pgsql-cygwin by date

  From Date Subject
Next Message Jason Tishler 2002-10-31 16:06:30 Re: Problem configuring Postgres under Cygwin
Previous Message Kjell-Olav Bjerknes 2002-10-31 15:11:47 Problem configuring Postgres under Cygwin

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2002-10-31 16:07:35 Re: [SQL] Returning a recordset and filling datatable in a .NET
Previous Message Robert Treat 2002-10-31 14:50:54 Re: psql history