简体   繁体   English

如何转换&#39; <unnamed portal 1> &#39;到VB.NET中的plpgsql函数的数据集

[英]How convert '<unnamed portal 1>' to dataset of a plpgsql function in VB.NET

I was learning some basics of PostgreSQL basics. 我正在学习PostgreSQL基础知识的一些基础知识。 while i am trying to return a resutset from PostgreSQL stored function to a VB.NET application i stuck with the following scenarios 当我尝试将PostgreSQL存储函数的resutset返回到VB.NET应用程序时,我遇到了以下情况

##--- my PostgreSQL function is ## ---我的PostgreSQL函数是
 CREATE OR REPLACE FUNCTION checkLogin( IN p_uname TEXT,IN p_pwd TEXT) RETURNS refCursor AS $BODY$ DECLARE ref refCursor; BEGIN OPEN ref FOR SELECT UserMaster.* FROM UserMaster WHERE username=p_uname AND userpwd=p_pwd AND coalesce(userdel,FALSE)=FALSE; RETUR ref; END; $BODY$ LANGUAGE PLPGSQL 
-- My VB function To return dataset is following -我的VB函数返回数据集如下
 Function CheckLogin(ByVal username As String,ByVal pwd As String) As DataSet Try Dim ds As New DataSet Dim conString As String="Server=localhost;port=5432;Database=myDB;UserId=postgres;password=postgres" Dim con As NpgsqlConnection=New NpgsqlConnection(ConString) con.open() Dim com As NpgsqlCommand=New NpgsqlCommand("select * from checkLogin('"+ username +"','"+ pwd +"')",con) Dim da As NpgsqlDataAdapter=New NpgsqlDataAdapter(com) da.Fill(ds) Return ds Catch ex As Exception Return Nothing End Try End Function 

From this function it just return 'unnamed portal 1' within a tag my question is how can i convert it into DataSet. 通过此功能,它仅在标签内返回“未命名的门户1”。我的问题是如何将其转换为DataSet。 its really helpful if anybody answer it and mention what i do wrong. 如果有人回答它并提到我做错了,那真的很有帮助。 I googled and read most of the article related with this. 我用Google搜索并阅读了与此相关的大部分文章。 But i didn't find a proper solution for this. 但是我没有为此找到合适的解决方案。 if there is a link please mention it to me and excuse me for this question. 如果有链接,请告诉我,对不起这个问题。

thanks in advance 提前致谢

If what you want is a function that returns a set of rows (much like a table), then your function should probably return a table (see the docs , or this question for an example) instead of a refcursor. 如果您想要的是一个返回一组行的函数(很像一个表),那么您的函数应该返回一个表(请参阅docs或示例中的问题 ),而不是返回器。

A refcursor is a server-side object which allows you to retrieve the query results in special ways (eg fetching a certain number of rows at a time, resetting it). refcursor是服务器端对象,允许您以特殊方式检索查询结果(例如,一次获取一定数量的行,将其重置)。 If your function returns a refcursor you will need to interact with it by sending further queries as described in the docs . 如果您的函数返回了refcursor,则您需要通过发送进一步的查询来与它进行交互,如docs中所述 It doesn't seem like your use-case warrants this complexity. 您的用例似乎并不能证明这种复杂性。

I changed my stored function like following 我改变了我的存储功能,如下所示

CREATE OR REPLACE FUNCTION checkLogin(
IN p_uname TEXT,IN p_pwd TEXT) RETURNS TABLE(uid INTEGER,uname CHARACTOR varying,utype integer) AS
$BODY$

    BEGIN 
        RETURN QUERY
        SELECT userId,userName,userType FROM UserMaster WHERE username=p_uname AND userpwd=p_pwd AND coalesce(userdel,FALSE)=FALSE;

    END;
$BODY$
LANGUAGE PLPGSQL

this pgSQL function works fine and returns resultset and can to convert it to dataset easily. 此pgSQL函数可以正常工作并返回结果集,并且可以轻松地将其转换为数据集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM