using System;
using System.Data;
using System.Data.OleDb;
class DatasetExample
{
public static void Main()
{
OLEDB();
}
public static void OLEDB()
{
//현재 폴더에 student.mdb가 있어야 합니다.(debug 아래...)
string cnString = ("Provider=MSDAORA;data source=oraclejava;User ID=scott;Password=tiger");
OleDbConnection OleCn = new OleDbConnection(cnString);
OleCn.Open();
string sql = "SELECT * FROM addrbook";
try
{
OleDbCommand OleCmd = new OleDbCommand(sql, OleCn);
OleDbDataAdapter OleDa = new OleDbDataAdapter(OleCmd);
DataSet ds = new DataSet();
OleDa.Fill(ds, "AddrBook");
DataTable dt = ds.Tables["AddrBook"];
Console.Write("\n\n");
foreach(DataColumn hdr in dt.Columns)
{
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");
}
Console.WriteLine("\n---------------------------------------------------");
foreach(DataRow dtr in dt.Rows)
{
Console.WriteLine(
dtr["name"].ToString() + "\t" +
dtr["addr"].ToString() + "\t" +
dtr["tel"].ToString());
}
}
catch(Exception e)
{
Console.WriteLine("Error: " + e);
}
}
}
댓글 없음:
댓글 쓰기