Exemplo n.º 1
0
        public static void ExecutarComandoSQL(string strComando)
        {
            SqlConnection con = BDSQL.AbrirConexao();

            using (SqlCommand command = new SqlCommand(strComando, con))
            { command.ExecuteNonQuery(); }

            BDSQL.FecharConexao();
        }
Exemplo n.º 2
0
        public static SqlDataReader ExecutarComandoLeituraSQLtoReader(string strComando)
        {
            SqlConnection con = BDSQL.AbrirConexao();
            SqlDataReader reader;
            SqlCommand    command = new SqlCommand(strComando, con);

            reader = command.ExecuteReader();

            return(reader);
        }
Exemplo n.º 3
0
        public static void ExecutarComandoSQL(string strComando, SqlParameter[] parametros)
        {
            FecharConexao();
            SqlConnection con = BDSQL.AbrirConexao();

            using (SqlCommand command = new SqlCommand(strComando, con))
            {
                command.Parameters.AddRange(parametros);
                command.ExecuteNonQuery();
            }

            BDSQL.FecharConexao();
        }
Exemplo n.º 4
0
        public static DataTable ExecutarComandoLeituraSQLDataTable(string strComando)
        {
            var dt = new DataTable();


            SqlConnection con = BDSQL.AbrirConexao();

            using (SqlCommand command = new SqlCommand(strComando, con))

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    dt.Load(reader);
                }

            BDSQL.FecharConexao();

            return(dt);
        }
Exemplo n.º 5
0
        public static List <Dictionary <string, string> > ExecutarComandoLeituraSQL(string strComando)
        {
            List <Dictionary <string, string> > registros = new List <Dictionary <string, string> >();
            SqlConnection con = BDSQL.AbrirConexao();

            using (SqlCommand command = new SqlCommand(strComando, con))

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Dictionary <string, string> registro = new Dictionary <string, string>();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            registro.Add(reader.GetName(i), reader[reader.GetName(i)].ToString());
                        }
                        registros.Add(registro);
                    }
                }

            BDSQL.FecharConexao();

            return(registros);
        }