使用npgsql调用pg-function

时间:2017-12-13 16:22:25

标签: npgsql

一个非常简单的功能:

CREATE OR REPLACE FUNCTION stzh.test() RETURNS refcursor AS $BODY$

declare 
   outcursor refcursor;
begin
   OPEN outcursor 
   FOR SELECT '-1' As "value1";

   return outcursor;

end;$BODY$

  LANGUAGE plpgsql

调用该函数的代码:

Dim pCon As NpgsqlConnection
        Dim pCommand As NpgsqlCommand
        Dim pDataReader As IDataReader

        pCon = New NpgsqlConnection(System.Configuration.ConfigurationManager.AppSettings("PG_connection"))
        pCon.Open()
        pCon.BeginTransaction()

        pCommand = pCon.CreateCommand
        With pCommand
            .CommandText = "stzh.test"
            .CommandType = CommandType.StoredProcedure
            pDataReader = .ExecuteReader
        End With

        While pDataReader.Read
            Console.WriteLine(pDataReader.GetName(0))
        End While

执行此代码会将函数的名称(" test")写入控制台。我希望将列的名称(" value1")写入控制台。

我错过了什么?

0 个答案:

没有答案