참고하세요~
간단한 콘솔 애플리케이션 입니다.
using System;
using System.Data;
using System.Data.OleDb;
using System.Data;
using System.Data.OleDb;
class DatasetExample
{
public static void Main()
{
OLEDB();
}
{
public static void Main()
{
OLEDB();
}
public static void OLEDB()
{
//아래 Data Source는 oracle설치 폴더 network/admin/tnsnames.ora 파일에 있는 접속을 원하는 DB의 별명 입니다.,
string cnString = @"Provider=MSDORA;data source=onj;User ID=scott;Password=tiger";
OleDbConnection OleCn = new OleDbConnection(cnString);
OleCn.Open();
OleCn.Open();
string sql = "SELECT * FROM emp";
try
{
OleDbCommand OleCmd = new OleDbCommand(sql, OleCn);
OleDbDataAdapter OleDa = new OleDbDataAdapter(OleCmd);
{
OleDbCommand OleCmd = new OleDbCommand(sql, OleCn);
OleDbDataAdapter OleDa = new OleDbDataAdapter(OleCmd);
DataSet ds = new DataSet();
OleDa.Fill(ds, "EMP");
OleCn.Close();
OleCn.Close();
DataTable dt = ds.Tables["EMP"];
Console.Write("\n\n");
Console.Write("\n\n");
foreach (DataColumn hdr in dt.Columns)
{
Console.Write("{0, -10}\t", hdr.ColumnName);
}
Console.WriteLine("\n---------------------------------------------------");
{
Console.Write("{0, -10}\t", hdr.ColumnName);
}
Console.WriteLine("\n---------------------------------------------------");
foreach (DataRow dtr in dt.Rows)
{
foreach (DataColumn dtc in dt.Columns)
{
Console.Write("{0, -10}", dtr[dtc.ColumnName].ToString().Trim());
Console.Write("\t");
}
Console.Write("\n");
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e);
}
}
}
[결과]
댓글 없음:
댓글 쓰기