Connection string of C# & Oracle


The following code may be useful for those tryin to do something with C# & Oracle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

//the connection string
string conn = “Data Source=XE;Persist Security Info=True;User ID=system;Password=yourpass;Unicode=True”;
try
{
OracleConnection oraConnection = new OracleConnection(conn);
oraConnection.Open();
string aaa = “select * from ACCOUNT_NAME”;              //the query string
OracleCommand command = oraConnection.CreateCommand();
command.CommandText = aaa;
command.ExecuteNonQuery();
OracleDataReader reader = command.ExecuteReader();
//object of OracleDataReader initialized
while (reader.Read())
{
Decimal NA = (Decimal)reader[“ACT_ID”];
Console.WriteLine(NA);
}
string ins = “insert into tablename values(‘values’)”;
command.CommandText =ins;
command.ExecuteNonQuery();


oraConnection.Close();     //close the connection for safety
}
catch (OracleException ex) {
Console.WriteLine(ex.ToString());    //Exception handling
}
Console.In.Read();

}
}
}

Advertisements