我第一次测试我与 Oracle 的连接。连接本身似乎有效。然而...
从 my_core.my_table 中选择前 1 个 ID
是我使用的句子
和上
retVal = cmd1.ExecuteScalar().ToString();
投掷
ORA-00923: 在预期的地方找不到 FROM 关键字
in Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode,
OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src
, String procedure, Boolean bCheck)
in Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, Oracle
Connection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx
, Object src, Boolean bCheck)
in Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Bool
ean fillRequest, CommandBehavior behavior)
in Oracle.DataAccess.Client.OracleCommand.ExecuteReader()
in Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()
in thiscs.Main() en C:\app\testuser\product\11.2.0\my\sample\thiscs.cs:line 44
这是代码:
// C#
using System;
using Oracle.DataAccess.Client;
using System.Data;
using System.Data.Common;
using System.Transactions;
class thiscs
{
static void Main()
{
string retVal = string.Empty;
string providerName = "Oracle.DataAccess.Client";
#region constr
string constr =
@"User Id=mytestuser;Password=mytestpass;Data Source=10.210.10.81:1521/my.svc.net;";
#endregion
// Get the provider factory.
DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
try
{
// Open a connection to the DB.
DbConnection conn1 = factory.CreateConnection();
conn1.ConnectionString = constr;
conn1.Open();
// Create a command to execute the sql statement.
DbCommand cmd1 = factory.CreateCommand();
cmd1.Connection = conn1;
cmd1.CommandText = @"SELECT TOP 1 ID FROM my_core.my_table";
// Execute the SQL statement to Select one rowfield in DB.
retVal = cmd1.ExecuteScalar().ToString();
Console.WriteLine("Field to be showed by cmd1: {0}", retVal);
// close and dispose the connection
conn1.Close();
conn1.Dispose();
cmd1.Dispose();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
我也试过
从 my_core.my_table 中选择前 1 个 [ID]
选择'嘿苹果,苹果,嘿'
两者都具有相同的结果:ORA-00923: FROM 关键字未在预期的地方找到
有任何想法吗?蒂亚!