Пример #1
0
        /// <summary>
        /// Retorna un datatable, recibe el sql a ejecutar
        /// </summary>
        /// <param name="pSelect"></param>
        /// <returns></returns>
        public static JsonDataResult TNS_QTConsulta(string Sql, string ConexionString = "")
        {
            JsonDataResult JsonResult = new JsonDataResult()
            {
                CONTENIDO = null
            };

            ConexionString = string.IsNullOrEmpty(ConexionString) ? GlobalVariables.ConexionMySql : ConexionString;

            MySqlConnection conexion = new MySqlConnection(ConexionString);
            MySqlCommand    command  = new MySqlCommand(Sql, conexion);

            try
            {
                conexion.Open();
                DataTable vDataTable = new DataTable();
                vDataTable.Load(command.ExecuteReader());

                JsonResult.CONTENIDO = JsonConvert.SerializeObject(vDataTable);
                JsonResult.SUCCESS   = true;
            }
            catch (Exception e)
            {
                JsonResult.CONTENIDO = HelperWs.getMessageException(e);
                JsonResult.SUCCESS   = false;
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
            }
            return(JsonResult);
        }
Пример #2
0
        /// <summary>
        /// Retorna un datatable, recibe el sql a ejecutar
        /// </summary>
        /// <param name="pSelect"></param>
        /// <returns></returns>
        public static JsonDataResult TNS_QTConsulta(string Sql, List <object> parametros, string ConexionString = "")
        {
            JsonDataResult JsonResult = new JsonDataResult()
            {
                CONTENIDO = null
            };

            ConexionString = string.IsNullOrEmpty(ConexionString) ? GlobalVariables.ConexionMySql : ConexionString;

            MySqlConnection conexion = new MySqlConnection(ConexionString);
            MySqlCommand    command  = new MySqlCommand(Sql, conexion);

            try
            {
                int i = 0;
                foreach (object value in parametros)
                {
                    string param = string.Concat("@param", i);
                    command.Parameters.AddWithValue(param, value);
                    i++;
                }
                conexion.Open();
                DataTable vDataTable = new DataTable();
                vDataTable.Load(command.ExecuteReader());
                JsonResult.CONTENIDO = JsonConvert.SerializeObject(vDataTable);
                JsonResult.SUCCESS   = true;
            }
            catch (Exception e)
            {
                JsonResult.CONTENIDO = HelperWs.getMessageException(e);
                JsonResult.SUCCESS   = false;
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
            }
            return(JsonResult);
        }