using System;
//Oracle .Net Provider
using Oracle.DataAccess.Client;
//ADO.Net
using System.Data;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
string strSQL = "Select empno, ename, job from emp";
//Create the connection
OracleConnection oConn = new OracleConnection("Data Source=ORCL;User ID=SCOTT;Password = TIGER");
//Create the OracleCommand object to execute the query
OracleCommand oCmd = new OracleCommand(strSQL, oConn);
//The OracledataAdapter is opened to communicate the DataSet Object
OracleDataAdapter oDa = new OracleDataAdapter(oCmd);
//Create the DataSet object this is an ADO Object
DataSet adoDs = new DataSet();
//Open the connection
oConn.Open();
//The OracleDataAdapter fill the query results into the DataSet
oDa.Fill(adoDs, "emp");
oConn.Close();
//Display the Column Names
foreach (DataColumn dc in adoDs.Tables[0].Columns)
Console.Write("{0,14}", dc.ColumnName);
Console.Write("\n");
foreach (DataColumn dc in adoDs.Tables[0].Columns)
Console.Write("{0,14}", "-----------");
Console.Write("\n");
//Display the data
foreach (DataRow dr in adoDs.Tables[0].Rows)
{
for (int i = 0; i<adoDs.Tables[0].Columns.Count; i++)
Console.Write("{0,14}", dr[i]);
Console.Write("\n");
}
}
}
}
댓글 없음:
댓글 쓰기