如何在SELECT statement like 'SELECT * FROM Employees'
使用 ODP.NET 的基础上实现简单的游标提取?
问问题
298 次
1 回答
1
所以这很简单。
首先OracleConnection
像这样创建类
OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
con.Open(); //opens connection
然后,您OracleCommand
首先通过将原始查询/存储过程作为第一个参数传递来定义和实例化,例如
因此,在您的特定情况下,它将是OracleCommand cmd = new OracleCommand("SELECT * FROM Employees", con
if (con.State == ConnectionState.Open)
{
using (OracleCommand cmd = new OracleCommand(<query>/<stored proc>, con))
{
cmd.CommandType = CommandType.StoredProcedure; //in case of stored proc
cmd.BindByName = true;
OracleDataReader reader;
try
{
reader = cmd.ExecuteReader();
while(reader.Read())
{
Console.WriteLine("field: {0}", reader.GetDecimal(0));
}
}
catch (OracleException e)
{
foreach (OracleError err in e.Errors)
{
//print errors
}
}
con.Close();
con.Dispose();
}
}
这是示例http://www.oracle.com/technetwork/articles/dotnet/williams-refcursors-092375.html
于 2016-03-20T17:29:20.523 回答