将 ASP.NET GridView 绑定到 Oracle SYS_REFCURSOR

发布于 2024-07-08 09:24:42 字数 458 浏览 8 评论 0原文

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

该过程如下所示:

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

现在 GridView 只是一个简单的框架:

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

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.

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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丑疤怪 2024-07-15 09:24:42

尝试如下:(未指定哪种语言)

    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

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
傲娇萝莉攻 2024-07-15 09:24:42
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()
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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文