Link to home
Start Free TrialLog in
Avatar of tscottt
tscottt

asked on

Returning Ref_cursor to dataview

I am trying to get the data grid (MyDataGrid) to populate.  I run the page with no errors.  Just for grins, I sent an invalid Oracle command, and sure enough, I got an oracle error returned - So I know the code is passing through to the Oracle DB.

I can't get the datagrid to populate/draw though.  I've tested my Stored Procedure otherwise (via SQL/Plus and Excel VBA) and it works fine.

Can somebody help me understand why MyDataGrid isn't showing up on my aspx page?

<%@ Page Language="c#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="Oracle.DataAccess.Client" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ Assembly Name="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" %>
<script runat="server">
 
    protected void Page_Load(Object sender, EventArgs e)
    
    {
    
      OracleConnection con = new OracleConnection("data source=myDatabase;user id=MyuserID;password=myPass;");
    
      con.Open();
    
      OracleCommand cmd = new OracleCommand("Pkg_CPU_Reports.Report_CPU_Histogram",con);
    
      OracleParameter oparam = cmd.Parameters.Add("ResultCursor", OracleDbType.RefCursor);
    
      oparam.Direction = ParameterDirection.Output;
    
       cmd.CommandType = CommandType.StoredProcedure;
    
      OracleDataAdapter adapter = new OracleDataAdapter(cmd);
    
      DataSet myset = new DataSet("ResultCursor");
    
      adapter.Fill(myset);
	  
	  DataGrid MyDataGrid = new DataGrid();
    
      MyDataGrid.DataSource=myset;
    
       MyDataGrid.DataBind();	
 
    }
</script>
<html>
 
 
 
<body>
 
<H1>Result Set</H1>
 
<form runat="server">
 
<asp:datagrid id="MyDataGrid" runat="Server"/>
 
</form>
 
</body>
 
</html>

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

How many DataTable and rows does the DataSet have?
Avatar of tscottt
tscottt

ASKER

About 10.
You didn't define any columns for the DataGrid.  If you are using ASP.NET 2.0, then I would suggest using the GridView, which can auto-generate columns from the data source.
Avatar of tscottt

ASKER

You're a champ for helping me!  I changed it to a GridView, but it still doesn't show a control (much less populate it with data).

As an experiment I changed : asp:GridView id="MyDataGrid"

to

asp: GridView id="nothing really"

And it behaved the same.  It's as if the MyDataGrid binding in the C## inline script isn't being recognized by the ASP:GridView.

 I also tried explicitly setting DataSourceID="myset" (the variable from the script) and DataSourceID="MyDataGrid", and neither of those worked.  At least they threw errors, though.

I'm probably missing something simple about how to bind my asp control to the control of the same name in the script.
Set the GridView's AutoGenerateColumns property to True.  DataSourceID is used with an SqlDataSource, ObjectDataSource, XmlDataSource, etc.
ASKER CERTIFIED SOLUTION
Avatar of tscottt
tscottt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial