Piccolo esempio che illustra un accesso al Database Oracle Tramite statement e una restituzione del numero di record presenti sulla tabella Authors in c#.
E' stato utilizzata la libreria OracleClient da referenziare nel progetto .Net in Visual Studio
//using System.Data.OracleClient;
private static void testConnectionDB()
{
OracleConnection conn = new OracleConnection(oraConn);
int intRecord = 0;
string str1="Florence";
string str2="Italy";
try
{
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select count(*) as numAuthors from Authors +
" where field1 =:strField1 and field2 =:strField2";
cmd.Parameters.AddWithValue("strField1", str1);
cmd.Parameters.AddWithValue("strField2", str2);
intRecord = Convert.ToInt32(cmd.ExecuteScalar());
}
catch (Exception ex)
{
log.Error(ex.Message);
}
finally
{
cmd.Dispose();
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}