[ C #, ADO . NET , 간단 한 윈 폼 , 오라클 로그인 예제 ] 간단히 ID , Password 를 입력 받 는 윈 폼 을 만들 고 오라클 DB 를 이용 하 여 로그인 을 하 는 예제 를 만들 어 보 자 . 로그인 성공 시 모 달창 으로 빈 윈도우 하나 띄움 . .. 먼저 윈도우 폼 Application 프로젝트 ( 이름 : Login ) 를 하나 생성 후 아래 처럼 파일 을   만들 어 보 자 .   생성 되 는 윈도우 폼 의 이름 을 FrmLogin . cs 로 변경 을 하 자 . 1 . 로그 파일 생성 을 위한 Log . cs 클래스 파일 을 추가 ( 오류 로 그 남기 기 위해 ) using System ; using System . IO ; namespace Login {     class Log     {         / / C 드라이브 에 dotnet 폴더 를 만들 자 .         public static void WriteLine ( string name , string e )         {             string filename = @" c : \ dotnet \" + name ;             string logtime = DateTime . Now . ToString ( ) ;             FileStream aFile = new FileStream ( filename , FileMode . Append ) ;             StreamWriter aWriter = new StreamWriter ( aFile , System . Text . Encoding . Default ) ;             aWriter . WriteLine ( "[" + logtime + "] ");             aWriter . WriteLine ( e ) ;             aWriter . Flush ( ) ;             aWriter . Close ( ) ;         }     }} 2 . 공통 DB 용 클래스 ( Program . cs ) using System ; using System . Data ; using System . Data . OleDb ; using System . Data . SqlTypes ; using System . Windows . Forms ; using System . Collections ; namespace Login {     public class Common _ DB     {         / / DataBaseConnection         public static OleDbConnection DBConnection ( )         {             OleDbConnection Conn ;             / / 아래 는 오라클 용 접속 문자열 , data source 애 는 tnsnames . ora 파일 에 있 는 Alias 명 을 넣 으면 됩니다 .             string ConStr = ( " Provider = MSDAORA ; data source = onj ; User ID = scott ; Password = tiger ");             Conn = new OleDbConnection ( ConStr ) ;             return Conn ;         }         / / DataSelect         public static OleDbDataReader DataSelect ( string sql , OleDbConnection Conn )         {             try             {                 OleDbCommand myCommand = new OleDbCommand ( sql , Conn ) ;                 return myCommand . ExecuteReader ( ) ;             }             catch ( Exception ex )             {                 / / Log File 에 출력                 Log . WriteLine ( " FrmLogin ", ex . ToString ( ) ) ;                 MessageBox . Show ( sql + "\ n " + ex . Message , " DataSelect ");                 return null ;             }             finally { }         }     }}   3 . FrmLogin . cs [ C # 코드 ] using System ; using System . Collections . Generic ; using System . ComponentModel ; using System . Data ; using System . Data . OleDb ; using System . Drawing ; using System . Linq ; using System . Text ; using System . Windows . Forms ; namespace Login {     public partial class FrmLogin : Form     {         private OleDbConnection LocalConn ;         public FrmLogin ( )         {             InitializeComponent ( ) ;         }         static void Main ( ) { Application . Run ( new FrmLogin ( ) ) ; }         private void button 1 _ Click ( object sender , EventArgs e )         {             OleDbDataReader myReader ;             string sql = null ;             try             {                 LocalConn = Common _ DB . DBConnection ( ) ;                 LocalConn . Open ( ) ;                 if ( txtID . Text == "" || txtPWD . Text == "")                 {                     MessageBox . Show ( " ID 또는 Password 를 입력 하 세요 . ..");                     return ;                 }                 sql = " select pwd from member ";                 sql += " where id = " + "'" + txtID . Text + "'";                 myReader = Common _ DB . DataSelect ( sql , LocalConn ) ;                 if ( myReader . Read ( ) )                 {                     if ( txtPWD . Text ! = myReader [ " pwd "]. ToString ( ) )                     {                         MessageBox . Show ( " Password 가 맞 지 않 습니다 . ..");                         return ;                     }                 }                 else                 {                     MessageBox . Show ( " 등록 되 지 않 은 ID 입니다 . ");                     return ;                 }                 / /----------- ID 가 PWD 가 맞 는 경우                 Form f = new Form ( ) ;                 f . Text = " 로그인 OK ";                 f . ShowDialog ( ) ;             }             catch ( Exception e 1 )             {                 Log . WriteLine ( " FrmLogin ", e 1 . ToString ( ) ) ;                 MessageBox . Show ( e 1 . ToString ( ) + sql , " FrmLogin : : 로그인 오류 ! ");             }         }         / / 패스워드 를 입력 하 고 엔터 키 를 입력 해도 로그인 디 되 도록         private void txtPWD _ KeyUp ( object sender , KeyEventArgs e )         {             if ( e . KeyCode == Keys . Enter )             {                 button 1 _ Click ( sender , e ) ;             }         }     }}[ 디자인 코드 ] namespace Login {     partial class FrmLogin     {         / // < summary >         / / / Required designer variable .         / // </ summary >         private System . ComponentModel . IContainer components = null ;         / // < summary >         / / / Clean up any resources being used .         / // </ summary >         / // < param name =" disposing "> true if managed resources should be disposed ; otherwise , false . </ param >         protected override void Dispose ( bool disposing )         {             if ( disposing && ( components ! = null ) )             {                 components . Dispose ( ) ;             }             base . Dispose ( disposing ) ;         }         # region Windows Form Designer generated code         / // < summary >         / / / Required method for Designer support - do not modify         / / / the contents of this method with the code editor .         / // </ summary >         private void InitializeComponent ( )         {             this . label 1 = new System . Windows . Forms . Label ( ) ;             this . label 2 = new System . Windows . Forms . Label ( ) ;             this . txtID = new System . Windows . Forms . TextBox ( ) ;             this . txtPWD = new System . Windows . Forms . TextBox ( ) ;             this . button 1 = new System . Windows . Forms . Button ( ) ;             this . SuspendLayout ( ) ;             / /              / / label 1             / /              this . label 1 . AutoSize = true ;             this . label 1 . Location = new System . Drawing . Point ( 48 , 21 ) ;             this . label 1 . Name = " label 1 ";             this . label 1 . Size = new System . Drawing . Size ( 16 , 12 ) ;             this . label 1 . TabIndex = 0 ;             this . label 1 . Text = " ID ";             / /              / / label 2             / /              this . label 2 . AutoSize = true ;             this . label 2 . Location = new System . Drawing . Point ( 48 , 56 ) ;             this . label 2 . Name = " label 2 ";             this . label 2 . Size = new System . Drawing . Size ( 31 , 12 ) ;             this . label 2 . TabIndex = 1 ;             this . label 2 . Text = " PWD ";             / /              / / txtID             / /              this . txtID . Location = new System . Drawing . Point ( 103 , 13 ) ;             this . txtID . Name = " txtID ";             this . txtID . Size = new System . Drawing . Size ( 179 , 21 ) ;             this . txtID . TabIndex = 2 ;             / /              / / txtPWD             / /              this . txtPWD . Location = new System . Drawing . Point ( 103 , 47 ) ;             this . txtPWD . Name = " txtPWD ";             this . txtPWD . Size = new System . Drawing . Size ( 179 , 21 ) ;             this . txtPWD . TabIndex = 3 ;             this . txtPWD . KeyUp += new System . Windows . Forms . KeyEventHandler ( this . txtPWD _ KeyUp ) ;             / /              / / button 1             / /              this . button 1 . Location = new System . Drawing . Point ( 321 , 21 ) ;             this . button 1 . Name = " button 1 ";             this . button 1 . Size = new System . Drawing . Size ( 86 , 47 ) ;             this . button 1 . TabIndex = 4 ;             this . button 1 . Text = " 로그인 ";             this . button 1 . UseVisualStyleBackColor = true ;             this . button 1 . Click += new System . EventHandler ( this . button 1 _ Click ) ;             / /              / / FrmLogin             / /              this . AutoScaleDimensions = new System . Drawing . SizeF ( 7 F , 12 F ) ;             this . AutoScaleMode = System . Windows . Forms . AutoScaleMode . Font ;             this . ClientSize = new System . Drawing . Size ( 448 , 105 ) ;             this . Controls . Add ( this . button 1 ) ;             this . Controls . Add ( this . txtPWD ) ;             this . Controls . Add ( this . txtID ) ;             this . Controls . Add ( this . label 2 ) ;             this . Controls . Add ( this . label 1 ) ;             this . Name = " FrmLogin ";             this . Text = " Form 1 ";             this . ResumeLayout ( false ) ;             this . PerformLayout ( ) ;         }         # endregion         private System . Windows . Forms . Label label 1 ;         private System . Windows . Forms . Label label 2 ;         private System . Windows . Forms . TextBox txtID ;         private System . Windows . Forms . TextBox txtPWD ;         private System . Windows . Forms . Button button 1 ;     }}