2013년 9월 4일 수요일

오라클자바커뮤니티 닷넷 강좌 , ODP.Net 데이터 Select 예제

오라클자바커뮤니티 닷넷 강좌 , ODP.Net 데이터 Select 예제

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");
                        }               
                }
        }
}


오라클자바커뮤니티 실전 개발 강좌 - 개인80% 환급


댓글 없음:

댓글 쓰기