C#连接orcle数据库

来源:互联网 发布:电脑看书软件阅读器 编辑:程序博客网 时间:2024/05/01 21:29

using    System; 
using    System.Collections.Generic; 
using    System.Text; 
using    System.Data.OracleClient; 
using    System.Data;

namespace    Common 

         public    class    DataAccess 
         { 
                 private    string    _connectionStr    =    " "; 
                 private    string    _userID    =    " "; 
                 private    OracleConnection    _conn    =    null; 
                 private    OracleCommand    _comm    =    null; 
                 private    OracleDataAdapter    _da    =    null;

                 public    DataAccess(string    dataSource,string    userID,string    password) 
                 { 
                         this._userID    =    userID; 
                          this._connectionStr    =    "data    source= "+dataSource+ ";user     id= "+userID+ ";password= "+password+ "; "; 
                         this._conn    =    new    OracleConnection(this._connectionStr); 
                         this._comm    =    new    OracleCommand(); 
                         this._comm.CommandType    =    CommandType.Text; 
                         this._comm.Connection    =    this._conn; 
                         this._da    =    new    OracleDataAdapter(); 
                         this._da.SelectCommand    =    this._comm; 
                 } 
                 ///    <summary> 
                 ///    关闭数据库连接 
                 ///    </summary> 
                 public    void    Close() 
                 { 
                         this._conn.Close(); 
                 } 
                 ///    <summary> 
                 ///    验证用户登陆是否成功 
                 ///    </summary> 
                 ///    <returns> </returns> 
                 public    bool    Login() 
                 { 
                         bool    returnValue    =    true; 
                         try 
                         { 
                                 this._conn.Open(); 
                         } 
                         catch 
                         { 
                                 returnValue    =    false; 
                         } 
                         finally 
                         { 
                                 if    (this._conn.State    ==    ConnectionState.Open) 
                                 { 
                                         this._conn.Close(); 
                                 } 
                         } 
                         return    returnValue; 
                 } 
         } 
}


0 0
原创粉丝点击