A simple data access layer to access different type of database. A simple wrapper will handle will support normal connection including transaction.
SQL Server MySQL SQLite
Oracle , ODBC and OLEDB
Always wrap the DBWrapper by utilizing using statement to ensure all connection has been dispose properly to prevent memory leak.
using (var dal = new DBWrapper("DBConnection"))
DBConnection is your webconfig connection name where this library will automatically find connectionstring and provider name.
<connectionStrings>
<add name="DBConnection" connectionString="Data Source=localhost;Initial Catalog=demo;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="DBSQLite" connectionString="Data Source=mydb.db;Version=3;" providerName="System.Data.Sqlite" />
</connectionStrings>
you will have the flexibility to use Stor Proc or Direct Query which require your needs.
using (var dal = new DBWrapper("DBConnection"))
{
try
{
var user = new User
{
FirstName = "First",
LastName = "Last",
Dob = DateTime.Now.AddDays(-3000),
IsActive = true
};
int count = dal.GetScalarValue("MY_STOR_PROC_NAME", CommandType.StoredProcedure);
Console.WriteLine("current total " + count.ToString());
-- skip for brevity
using (var dal = new DBWrapper("DBConnection"))
{
try
{
var user = new User
{
FirstName = "First",
LastName = "Last",
Dob = DateTime.Now.AddDays(-3000),
IsActive = true
};
int count = dal.GetScalarValue("select count(*) from table", CommandType.Text);
Console.WriteLine("current total " + count.ToString());
-- skip for brevity
for full example you can refer C# Example and for VB.NET VB.NET Example
Thank you and happy Coding 💗 from Malaysia