internal class sqlHelper
{
string connectionString = ConfigurationManager.ConnectionStrings["local"].ConnectionString;
//ABM CON CONECTADO
public bool ABMConectado (string procedure, SqlParameter[] parametros)
{
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand comando = new SqlCommand())
{
comando.Connection = connection;
comando.CommandType = CommandType.StoredProcedure;
comando.CommandText = procedure;
comando.Parameters.AddRange(parametros);
connection.Open();
return comando.ExecuteNonQuery()>0;
}
}
//LECTURA CON CONECTADO
public DataTable LeerConectado(string procedure, SqlParameter[] parametros)
{
DataTable table = new DataTable();
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand comando = new SqlCommand())
{
comando.Connection = connection;
comando.CommandType = CommandType.StoredProcedure;
comando.CommandText = procedure;
comando.Parameters.AddRange(parametros);
connection.Open();
SqlDataReader reader = comando.ExecuteReader();
table.Load(reader);
return table;
}
}
//LECTURA CON DESCONECTADO
public DataTable LeerDesconectado(string procedure,SqlParameter[] parametros)
{
DataTable table = new DataTable();
using (SqlConnection connection=new SqlConnection(connectionString))
{
SqlCommand comando = new SqlCommand();
comando.Connection = connection;
comando.CommandType = CommandType.StoredProcedure;
comando.CommandText = procedure;
comando.Parameters.AddRange(parametros);
SqlDataAdapter adapter = new SqlDataAdapter(comando);
adapter.Fill(table);
}
return table;
}