#region Copyright
/*
* (c) 2006 Jozef Izso
*
* This program code is free of use.
* It's provided as is without any waranties.
*
* You need to add logging to the catchs blocks and
* load Connection String.
*/
#endregion
using System;
using System.Data;
using System.Data.SqlClient;
///
///
///
/// Jozef Izso
public static class DbLayer
{
public delegate T DataReaderHandle(SqlDataReader reader);
///
///
///
/// Návratový typ metódy. Generická metóda musí
/// byť tohto typu.
/// Metóda, ktorá vytvorí pomocou predaného
/// objektu inštanciu objektu .
///
///
///
public static T ExecuteReader(DataReaderHandle handle, String procedure, params SqlParameter[] parameters)
{
SqlConnection conn = null;
SqlCommand cmd = new SqlCommand(procedure, conn);
cmd.CommandType = CommandType.StoredProcedure;
T ret = default(T);
SqlDataReader reader = null;
try
{
conn.Open();
reader = cmd.ExecuteReader();
// zavolá obslužnú metódu
ret = handle(reader);
}
catch (SqlException ex)
{
//LogSqlException(cmd, ex);
}
catch (Exception ex)
{
// zalogovanie chyby z obslužnej metódy handle()
}
finally
{
if (reader != null)
{
reader.Close();
reader.Dispose();
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
return ret;
}
}