Automated teller machine emulation.
using System;
using System.Data;
using System.Data.SqlClient;
using log4net;
namespace Impexpdata.Core
{
public class DataAccess
{
private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public SqlConnection GetConn()
{
if (string.IsNullOrEmpty(Properties.SqlConnectionString))
{
Log.Error("SQL connection string not found.");
throw new ArgumentNullException("SQL connection string not found.");
}
var conn = new SqlConnection(Properties.SqlConnectionString);
if (conn.State != ConnectionState.Open)
conn.Open();
return conn;
}
public void ExecuteSql(SqlCommand cmd)
{
using (var conn = GetConn())
{
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
public DataTable FillDataTable(SqlCommand cmd)
{
cmd.Connection = GetConn();
using (var dataReader = cmd.ExecuteReader())
{
var dataTable = new DataTable();
dataTable.Load(dataReader);
cmd.Connection.Close();
return dataTable;
}
}
}
}