[ADO.NET]CommandType.TableDirect예제,오라클EMP테이블 데이터 SELECT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApplication20
{
class Program
{
static void Main(string[] args)
{
OleDbConnection myOleDbConnection =
new OleDbConnection("Provider=MSDAORA;data source=onj;User ID=scott;Password=tiger");
OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand();
//CommendText에 직접 테이블 명을 기술하겠다는 의미
myOleDbCommand.CommandType = CommandType.TableDirect;
myOleDbCommand.CommandText = "EMP"; //테이블명이다.
myOleDbConnection.Open();
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
//전체 EMP 테이블의 데이터중 2건만 출력하자.
for (int count = 1; count <= 2; count++) {
myOleDbDataReader.Read();
Console.WriteLine("myOleDbDataReader[\" EMPNO\"] = " + myOleDbDataReader["EMPNO"]);
Console.WriteLine("myOleDbDataReader[\" ENAME\"] = " + myOleDbDataReader["ENAME"]);
Console.WriteLine("myOleDbDataReader[\" SAL\"] = " + myOleDbDataReader["SAL"]);
}
myOleDbDataReader.Close();
myOleDbConnection.Close();
}
}
}
[결과]
myOleDbDataReader[" EMPNO"] = 2141
myOleDbDataReader[" ENAME"] = 홍길동
myOleDbDataReader[" SAL"] =
myOleDbDataReader[" EMPNO"] = 2142
myOleDbDataReader[" ENAME"] = Cary2
myOleDbDataReader[" SAL"] =
댓글 없음:
댓글 쓰기