Esempio n. 1
0
        public static DataTable ExecutaSelect(string sql, SqlParameter[] parametros)
        {
            using (SqlConnection cx = ConexaoBD.GetConexao())
            {
                using (SqlDataAdapter adapter = new SqlDataAdapter(sql, cx))
                {
                    if (parametros != null)
                    {
                        adapter.SelectCommand.Parameters.AddRange(parametros);
                    }
                    DataTable tabela = new DataTable();
                    adapter.Fill(tabela);

                    return(tabela);
                }
            }
        }
Esempio n. 2
0
        public static int ExecutaSQL(string sql, SqlParameter[] parametros)
        {
            using (SqlConnection conexao = ConexaoBD.GetConexao())
            {
                using (SqlCommand comando = new SqlCommand(sql, conexao))
                {
                    comando.Parameters.AddRange(parametros);
                    comando.ExecuteNonQuery();

                    comando.CommandText = "select @@identity";
                    object o = comando.ExecuteScalar();
                    if (o != null)
                    {
                        return(Convert.ToInt32(o));
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
        }