Example #1
0
        public DataTable GetTabla(string Procedimiento, string[] NombreParametros, params Object[] valparametros)
        {
            /////
            //Solo para consultas
            DataTable    dt  = new DataTable();
            MySqlCommand cmd = new MySqlCommand();
            Bd           con = new Bd();

            cmd.Connection  = con.GetConexion();
            cmd.CommandText = Procedimiento;
            cmd.CommandType = CommandType.StoredProcedure;
            if (Procedimiento.Length != 0 && NombreParametros.Length == valparametros.Length)
            {
                int i = 0;
                foreach (string parametro in NombreParametros)
                {
                    cmd.Parameters.AddWithValue(parametro, valparametros[i++]);
                }
                try
                {
                    MySqlDataReader dr = cmd.ExecuteReader();
                    dt.Load(dr);
                    return(dt);
                }
                catch (Exception e)
                {
                    return(dt);
                }
                finally {
                    Bd cone = new Bd();
                    cone.CerrarConexion();
                }
            }
            return(dt);
        }
Example #2
0
        public int ExeProceVenta(string Procedimiento, string[] NombreParametros, params Object[] valparametros)
        {
            Bd con = new Bd();

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = Procedimiento;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = con.GetConexion();
            MySqlTransaction tranOperaciones = null;

            tranOperaciones = cmd.Connection.BeginTransaction();
            cmd.Transaction = tranOperaciones;


            if (Procedimiento.Length != 0 && NombreParametros.Length == valparametros.Length)
            {
                int i = 0;
                foreach (string parametro in NombreParametros)
                {
                    cmd.Parameters.AddWithValue(parametro, valparametros[i++]);
                }

                try
                {
                    int x;
                    tranOperaciones.Commit();
                    x = Convert.ToInt32(cmd.ExecuteScalar());


                    return(x);
                }
                catch (Exception e)
                {
                    tranOperaciones.Rollback();
                }
                finally
                {
                    Bd cone = new Bd();
                    cone.CerrarConexion();
                }
            }
            return(0);
        }