C# .NET Core 连接Oracle数据库之使用Oracle.ManagedDataAccess.Core

使用C#读取Oracle数据库

using System;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;

namespace OracleConnectionExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "Data Source=;User Id=;Password=";

            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                connection.Open();

                string query = "SELECT * FROM your_table";
                using (OracleCommand command = new OracleCommand(query, connection))
                {
                    using (OracleDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            // 解析读取到的每一列数据和字段
                            Dictionary<string, object> rowData = new Dictionary<string, object>();
                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                string columnName = reader.GetName(i);
                                object columnValue = reader.GetValue(i);
                                rowData.Add(columnName, columnValue);
                            }

                            // 使用 rowData 进行进一步处理
                            foreach (var kvp in rowData)
                            {
                                Console.WriteLine($"{kvp.Key}: {kvp.Value}");
                            }
                        }
                    }
                }
            }
        }
    }
}

你可能感兴趣的:(ASP.NET,sql,C#,数据库,c#,.netcore)