【发布时间】:2021-01-14 17:42:45
【问题描述】:
我正在尝试使用 c# 连接到 Oracle 数据库。我看到我有两个选择:
using System.Data.OracleClient;
要么
using ADODB;
我对 MySQL 很熟悉,这就是为什么我更容易理解和使用 OracleClient 的原因。但是,我看到当我使用它时,c# 说它已被弃用。这让我想知道我的 OracleClient 代码在 1-2 年后是否还能正常工作。
我该怎么办?
以下是我使用 OracleClient 的代码:
public class DataHelper
{
public OracleConnection connection;
String connectionString;
public DataHelper()
{
connectionString = "this should be connection string";
connection = new OracleConnection(connectionString);
}
public List<Machine> GetAllMachines()
{
List<Machine> temp= new List<Machine>();
using (OracleConnection connection = new OracleConnection(connectionString))
{
string queryString = "SELECT * FROM MACHINES";
OracleCommand command = new OracleCommand(queryString);
try
{
command.Connection = connection;
connection.Open();
command.CommandType = CommandType.Text;
//command.ExecuteNonQuery();
OracleDataReader reader = command.ExecuteReader();
int machineNr, nrOfLinesPerCm;
double cycleTime, currentTime, heightOfLamallae;
string machineType;
while (reader.Read())
{
machineNr = Convert.ToInt32(reader["MACHINE_NR"]);
cycleTime = Convert.ToDouble(reader["CYCLE_TIME"]);
currentTime = Convert.ToDouble(reader["CURRENT_TIME"]);
machineType = Convert.ToString(reader["TYPE"]);
nrOfLinesPerCm = Convert.ToInt32(reader["NR_OF_LINES_PER_CM"]);
heightOfLamallae = Convert.ToDouble(reader["HEIGHT_OF_LAMALLAE"]);
temp.Add(new Machine(machineNr, cycleTime, currentTime, nrOfLinesPerCm, heightOfLamallae, machineType));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
return temp;
}
}
如果您推荐 ADODB,您将如何使用它来实现它?
【问题讨论】:
标签: c# database adodb oracleclient