How To Create Universal DAL to connect with any database
I am new to .net i need a universal database accessing dal layer with it must be coding friendly
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Narasimha Reddy ChennupalliRank #1,163 · 1.6K reputationPosted Jul 4, 2015, 9:40 AM EDT
Create one Interface to access for different databases. The below steps help you to maintain universal DAL.
Steps:
1. Create Interface with the name IDataAccess
Public Interface IDataAccess
{
void DbConnection();
DataTable GetAllData();
bool InsertData();
bool UpdateData();
bool DeleteData();
}
2. Implement the interface for Sql database access with the class name DataAcessSql.cs and implement all the methods of IDataAccess interface
Public class DataAccessSql:IDataAccess
{
Public void DbConnection()
{
// write the code for Sql connection
}
Public DataTable GetAllData()
{
// write the code to get data from Sql database.
}
Public bool InsertData()
{
// write the code for inserting data into Sql database.
}
Public bool UpdateData()
{
// write the code for updating data into Sql database.
}
Public bool DeleteData()
{
// write the code for deleting data from Sql database.
}
}
3. Implement the interface for Oracle database access with the class name DataAcessOracle.cs and implement all the methods of IDataAccess interface
Public class DataAccessOracle:IDataAccess
{
Public void DbConnection()
{
// write the code for Oracle database connection
}
Public DataTable GetAllData()
{
// write the code to get data from Oracle database.
}
Public bool InsertData()
{
// write the code for inserting data into Oracle database.
}
Public bool UpdateData()
{
// write the code for updating data into Oracle database.
}
Public bool DeleteData()
{
// write the code for deleting data from Oracle database.
}
}
In this way we can maintain universal DA. We cannot get any conflicts by using different databases.
I hope this will help you to matain universal DAL, let me know if you have any queries on this.