Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect to oracle XE using c# 2010 express [closed]

Tags:

c#

Just startted with c#. not sure the express version supports connection to oracle or not. if it does, could anyone let me know the steps to do it?

Thanks guys.

like image 780
William Avatar asked Jan 29 '26 05:01

William


1 Answers

Use the ODP .NET ADO .NET Provider. You can see an example of how to use it here.

Copied from the example

using System;
using System.Data;
using Oracle.DataAccess.Client;

...

// Create the connection object
OracleConnection con = new OracleConnection();

// Specify the connect string
// NOTE: Modify User Id, Password, Data Source as per your database set up
con.ConnectionString = "User Id=userid;Password=password;Data Source=dbinstance;";

try
{
  // Open the connection
  con.Open();
  Console.WriteLine("Connection to Oracle database established!");
  Console.WriteLine(" ");
} 
catch (Exception ex)
{
 Console.WriteLine(ex.Message);
}

string cmdQuery = "SELECT empno, ename FROM emptab";

// Create the OracleCommand object
OracleCommand cmd = new OracleCommand(cmdQuery);
cmd.Connection = con;
cmd.CommandType = CommandType.Text;

try
{
  // Execute command, create OracleDataReader object
  OracleDataReader reader = cmd.ExecuteReader();
  while (reader.Read())
  {
    // Output Employee Name and Number
    Console.WriteLine("Employee Number: " + 
                    reader.GetDecimal(0) + 
                                    " , " +
                       "Employee Name : " +


                      reader.GetString(1));
  }
}
catch (Exception ex) 
{
  Console.WriteLine(ex.Message);
} 
finally
{
  // Dispose OracleCommand object
  cmd.Dispose();


  // Close and Dispose OracleConnection object
  con.Close();
  con.Dispose(); 
}
like image 189
ta.speot.is Avatar answered Jan 31 '26 17:01

ta.speot.is



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!