public void ejecutarSp(string nombreSp, SqlParametros parametros)
 {
     _conexion = new SqlConnection(_cadenaConexion);
     try
     {
         _conexion.Open();
         SqlCommand sqlCommand = new SqlCommand(nombreSp, _conexion);
         sqlCommand.CommandType = CommandType.StoredProcedure;
         foreach (SqlParameter parametro in parametros.Parametros)
         {
             sqlCommand.Parameters.Add(parametro);
         }
         sqlCommand.ExecuteNonQuery();
     }
     catch (SqlException ex)
     {
         throw ex;
     }
     catch (Exception ex2)
     {
         throw ex2;
     }
     finally
     {
         if (_conexion.State != 0)
         {
             _conexion.Close();
         }
     }
 }
        public DataTable ejecutarSpDatos(string nombreSp, SqlParametros parametros)
        {
            _conexion = new SqlConnection(_cadenaConexion);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            DataTable      dataTable      = new DataTable();

            try
            {
                _conexion.Open();
                SqlCommand sqlCommand = new SqlCommand(nombreSp, _conexion);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                foreach (SqlParameter parametro in parametros.Parametros)
                {
                    sqlCommand.Parameters.Add(parametro);
                }
                sqlDataAdapter.SelectCommand = sqlCommand;
                sqlDataAdapter.Fill(dataTable);
                return(dataTable);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex2)
            {
                throw ex2;
            }
            finally
            {
                if (_conexion.State != 0)
                {
                    _conexion.Close();
                }
            }
        }
        public DataSet ejecutarSpDataSet(string nombreSp, SqlParametros parametros, ref int totalRegistros)
        {
            _conexion = new SqlConnection(_cadenaConexion);
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            DataSet        dataSet        = new DataSet();

            try
            {
                _conexion.Open();
                SqlCommand sqlCommand = new SqlCommand(nombreSp, _conexion);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                foreach (SqlParameter parametro in parametros.Parametros)
                {
                    sqlCommand.Parameters.Add(parametro);
                }
                sqlDataAdapter.SelectCommand = sqlCommand;
                sqlDataAdapter.Fill(dataSet);
                totalRegistros = Convert.ToInt32(sqlCommand.Parameters["@totalRegistros"].Value);
                return(dataSet);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex2)
            {
                throw ex2;
            }
            finally
            {
                if (_conexion.State != 0)
                {
                    _conexion.Close();
                }
            }
        }