将 ASP.NET GridView 绑定到 Oracle SYS_REFCURSOR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/234657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:24:22  来源:igfitidea点击:

Binding ASP.NET GridView to an Oracle SYS_REFCURSOR

asp.netoraclegridviewsys-refcursor

提问by jamminjulia

We have a Procedure in Oracle with a SYS_REFCURSOR output parameter that returns the data we want to bind to an ASP.NET GridView control. I've seen this done before but I can't find the original reference I used to solve the problem.

我们在 Oracle 中有一个带有 SYS_REFCURSOR 输出参数的过程,该参数返回我们想要绑定到 ASP.NET GridView 控件的数据。我以前见过这样做,但我找不到用于解决问题的原始参考。

Here is what the procedure looks like:

过程如下:

create or replace PROCEDURE GETSOMEDATA
(
    P_Data OUT SYS_REFCURSOR
)
AS
BEGIN
    OPEN P_Data FOR SELECT * FROM SOMETABLE;
END GETSOMEDATA;

And for now the GridView is just bare-bones:

现在 GridView 只是最基本的:

<asp:GridView ID="grdData" runat="server" AutoGenerateColumns="true"></asp:GridView>

采纳答案by Brian Schmitt

Try something like: (didn't specify which language)

尝试类似:(没有指定哪种语言)

    Public Function GetSomeData() as DataTable
        Dim OrclConn as New OracleConnection("Connectionstring")
        Dim OrclCmd as New Oraclecommand("GETSOMEDATA", OrclConn)
        OrclCmd.CommandType = CommandType.StoredProcedure
        OrclCmd.Parameters.Add("P_Data", OracleType.Cursor).Direction = ParameterDirection.Output 'Or ParameterDirection.ReturnValue

        Dim OrclDA as New OracleDataAdapter(OrclCmd)
        Dim RtnTable as DataTable
        OrclConn.Open
        OrclDA.Fill(RtnTable)
        OrclConn.Close

        Return RtnTable
    End Function

回答by balexandre

just GooglingIt trying to find out an answer for you, I come across this article.

只是谷歌搜索试图为你找到答案,我遇到了这篇文章

maybe it can help you on this matter.

也许它可以帮助你解决这个问题。

回答by Brian Schmitt

Dim oracon As New OracleConnection("User Id=developer;Password=developer;Data Source=orcl;")
        Dim ds As New Data.DataSet
        Dim qry As String
        oracon.Open()
        qry = "select * from Employee"
        Dim adp As New OracleDataAdapter(qry, oracon)
        adp.Fill(ds)
        GridView1.DataSource = ds
        GridView1.DataBind()
        oracon.Close()