Пример #1
0
        public DataTable getDatos(string procedimiento,

         string[] nomparametros, params Object[] valparametros)

        {

            DataTable dt = new DataTable();

            SqlCommand cmd = new SqlCommand();

            Conexion con = new Conexion();

            cmd.Connection = con.conectar();

            cmd.CommandText = procedimiento;

            cmd.CommandType = CommandType.StoredProcedure;

            if (nomparametros.Length != 0 && nomparametros.Length == valparametros.Length)

            {

                int i = 0;

                foreach (string parametro in nomparametros)

                    cmd.Parameters.AddWithValue(parametro, valparametros[i++]);

            }

            try

            {

                SqlDataReader dr = cmd.ExecuteReader();

                dt.Load(dr);

                return dt;

            }

            catch (Exception)

            { }

            return dt;





        }
Пример #2
0
        public int Ejecutar(string procedimiento,

           string[] nomparametros, params Object[] valparametros)

        {

            DataTable dt = new DataTable();

            SqlCommand cmd = new SqlCommand();

            Conexion con = new Conexion();

            cmd.Connection = con.conectar();

            cmd.CommandText = procedimiento;

            cmd.CommandType = CommandType.StoredProcedure;

            if (nomparametros.Length != 0 && nomparametros.Length == valparametros.Length)

            {

                int i = 0;

                foreach (string parametro in nomparametros)

                    cmd.Parameters.AddWithValue(parametro, valparametros[i++]);

            }

            try

            {

                return cmd.ExecuteNonQuery();

            }

            catch (Exception)

            { }

            return 0;





        }