Ejemplo n.º 1
0
        public static DataTable QueryDt(string sql)
        {
            using (OracleConnection con = new OracleConnection(connStr))
            {
                using (OracleCommand cmd = con.CreateCommand())
                {
                    try
                    {
                        con.Open();
                        cmd.BindByName = true;
                        //SQL查询语句
                        cmd.CommandText = sql;

                        OracleDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            Console.WriteLine("用户名: " + reader.GetString(0));
                        }

                        Console.WriteLine();
                        Console.WriteLine("Press 'Enter' to continue");

                        reader.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (null != con || !con.Disposed())
                        {
                            con.Dispose();
                        }
                    }
                }
            }
        }