(C#,WPF,¤ë‌¼´,ODP.NETˆ œ)C#,WPFëœ EMP …Œ‌´ë¸” ë°‌´„°ë¥¼ ë°‌´„° ë°”‌¸ë”©‌„ ‌´©•—¬

  • View
    242

  • Download
    13

Embed Size (px)

Text of (C#,WPF,¤ë‌¼´,ODP.NETˆ œ)C#,WPFëœ EMP...

PowerPoint

C#, WPF, ADO.NETXAML, Oracle ODP.NET (topcredu.co.kr),

Oracle Develpoer Tools ODP.NET DB EMP ListView .Visual Studio 2015 ODP.NET Oracle Developer Tool for Visual Studio 2015 . ( http://www.oracle.com/technetwork/topics/dotnet/downloads/odacmsidownload-2745497.html ) NETWORK\Admin tnsnames.ora Oracle Server ONJ = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = onj) DB ) )

WPF ( : WpfOracleTest) : -> -> %ORACLE_HOME%\ODP.NET\bin\2.x\Oracle.DataAccess.dll . PC 64Bit 10 -> (Target Platform) x64 . (32Bit )

EmpViewModel.cs(1)using System;using System.ComponentModel;using System.Windows.Input;namespace WpfOracleTest{ public class EmpViewModel : INotifyPropertyChanged { int empno = 0; string ename = string.Empty; string job = string.Empty;// public event PropertyChangedEventHandler PropertyChanged; // public public int Empno { get { return empno; } set { this.empno = value; } } // public public string Ename { get { return ename; } set { this.ename = value; } }

EmpViewModel.cs(2) // public public string Job { get { return job; } set { this.job = value; } } protected void OnPropertyChanged(string propertyName) { // . if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }}

MainWindow.xaml(1)

MainWindow.xaml(2)

MainWindow.xaml(3)

MainWindow.xaml.cs(1)using System;using System.Collections.Generic;using System.Windows;using System.Data;using Oracle.DataAccess.Client;namespace WpfOracleTest { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } OracleConnection conn;private void DB_Connect(object sender, RoutedEventArgs e) { try { string strCon = "data source=onj;User ID=scott;Password=tiger"; conn = new OracleConnection(strCon); conn.Open(); MessageBox.Show("DB Connection OK!"); } catch(Exception error) { MessageBox.Show(error.ToString()); } }

MainWindow.xaml.cs(2)private void Select_Emp(object sender, RoutedEventArgs e) { string sql = "select empno, ename, job from emp "; OracleCommand comm = new OracleCommand(); if(conn == null) DB_Connect(this, null); comm.Connection = conn; comm.CommandText = sql; OracleDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection); List emps = new List();while (reader.Read()) { emps.Add(new EmpViewModel() { Empno = reader.GetInt32(reader.GetOrdinal("empno")), Ename = reader.GetString(reader.GetOrdinal("ename")), Job = reader.GetString(reader.GetOrdinal("job")) }); } lstView.ItemsSource = emps; reader.Close(); } }}