program against Oracle

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone point me to some example ASP.NET apps that use Oracle has a backend and C# as the language?

I need to figure out how to populate a drop down, and then a datagrid depending on what the user selected in the drop down box.


thx
 
What you'll need first is the Oracle data provider either from Oracle or from Microsoft. All the C# code will look the same with the exception that the namespace is System.Data.OracleClient instead of System.Data.Sql. I believe there are code examples with both of these providers. But to get you started...

Instead of creating Sql* objects you create Oracle* objects.

If you plan to use Oracle stored procedures to return record sets you'll need to look up how to return "ref cursors" from Oracle.

It looks something like this, declare a type:
type myCursorType is ref cursor;

Your Oracle procedures will return this cursor type:
procedure MyProc(outData out myCursorType)

To return the recordset from within the Oracle stored procedure use:
open outData for "your select statement"

Now for C# code.

Unlike SqlServer stored procedures you have to setup an out parameter in your Command object's parameter collection to hold the recordset.
OracleParameter outData = new OracleParameter("outData", OracleType.Cursor);
outData.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(outData);

Create your OracleDataAdapter and fill your dataset like you would if you were using SqlDataAdapters.

HTH
 
I have the oracle data provider, i currenlty have the app in VB.NET i want to convert it over to C#.
is there some example code on this? I created C# code to connect to the DB and that works fine, and i also have my drop down populated, now how can i populate the grid depending on what the user selected from the drop down?
In C#
 
The code for C# should be almost identical to the VB code. The biggest difference will be how the event is wired up to code. All the other code dataGrid.DataBind() etc... should be the same, assuming you're using data binding. Another difference you may encounter is array indexers:
C#: []
VB: ( )

For event wiring the easiest thing to do is right click on the combobox and select properties. In the properties box click on the lightning bolt button. In the SeletedIndexChanged event type in the name of the method that will be called when the event fires. When you hit return the IDE will take back to the code window with a method set up and ready to code.

If you wish to see how the event is actually wired to the method expand the "Windows Form Designer generated code" region. In the InitializeComponent method you'll see something like:
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.Test);

I hope this gets you a little closer to where you want to go.
 
Back
Top