0% found this document useful (0 votes)
20 views

abm Con Conectado: Sqlhelper

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

abm Con Conectado: Sqlhelper

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

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;
}

You might also like