注意:一、Common類中的引用添加:右鍵--添加引用--.NET--選擇對應的引用服務器
二、各層之間引用互相添加(這個就沒必要多說了,三層最基礎部分)app
三、在添加 Oracle 引用時候須要單獨下載一個 Oracle.ManagedDataAccess.dllide
四、DBAccessLayer 項目裏的代碼能夠不用理解,會調用就行spa
五、配置文件代碼:.net
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DatabaseType" value="ORACLE" /> <!--<add key="DatabaseType" value="SQL" /> <add key="DatabaseType" value="OLEDB" /> <add key="DatabaseType" value="ODBC" />--> <!--本地服務器--> <add key="OracleUid" value="uname" /> <add key="OraclePwd" value="upwd" /> <add key="OracleDataSource" value="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.8.200)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=test)))" /> <add key="SqlServerServer" value="." /> <add key="SqlServerDatabase" value="hotel" /> <add key="SqlServerUid" value="sa" /> <add key="SqlServerPwd" value="sa" /> <add key="OleDbProvider" value="Microsoft.jet.oledb.4.0" /> <add key="OleDbDataSource" value="D:\test.mdb" /> <add key="OdbcDriver" value="Microsoft Access Driver (*.mdb)" /> <add key="OdbcDBQ" value="d:\test.mdb" /> <add key="ClientSettingsProvider.ServiceUri" value="" /> </appSettings> </configuration>
主窗體查詢代碼:code
//查詢全部用戶 private void btnSelect_Click(object sender, EventArgs e) { try { dgvUser.DataSource = MyProjectBLL.Manage.GetAllUser().Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
BLL層對應GetAllUser()代碼:orm
//查看會員信息 public static DataSet GetAllUser() { return MyProjectDAL.Service.GetAllUser(); }
DAL層對應GetAllUser()代碼:xml
//查看會員信息 public static DataSet GetAllUser() { string strSql = string.Format("select * from h_manager"); IDBAccess dbAccess = DBAccessLayer.DBFactory.GetDBAccess(); return dbAccess.ExecuteDataSet(strSql, CommandType.Text, null); }
備註:三層相互調用,有條不紊。blog
根據本身的業務需求拓展。utf-8
源碼下載地址:源代碼