本文整理汇总了C#中System.Data.OracleClient.OracleCommand.ExecuteOracleScalar方法的典型用法代码示例。如果您正苦于以下问题:C# OracleCommand.ExecuteOracleScalar方法的具体用法?C# OracleCommand.ExecuteOracleScalar怎么用?C# OracleCommand.ExecuteOracleScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.OracleClient.OracleCommand
的用法示例。
在下文中一共展示了OracleCommand.ExecuteOracleScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteOracleScalar
public object ExecuteOracleScalar(OracleCommand command)
{
PrepareCommand(command);
try
{
object result = command.ExecuteOracleScalar();
#if DEBUG
DatabaseLog.WriteInfo(command);
#endif
return result;
}
catch (Exception e)
{
DatabaseLog.WriteError(e.Message, command);
throw;
}
}
示例2: ExecuteScalarByTransaction
/// <summary>
/// 执行一个OracleCommand(返回一个结果object) /// </summary>
/// <param name="connection">有效的 OracleConnection</param>
/// <param name="sqlString">SQL</param>
/// <param name="parameterValues">以一个数组的形式返回OracleParameters ,如果没有参数即为null</param>
/// <returns></returns>
public object ExecuteScalarByTransaction(OracleConnection connObjection, string sqlString, OracleParameter[] parameterValues)
{
OracleCommand cmd = new OracleCommand();
try
{
if (connObjection.State != ConnectionState.Open)
{
connObjection.Open();
}
cmd.Connection = connObjection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlString;
if (Transaction != null)
{
cmd.Transaction = Transaction;
//Transaction = connObjection.BeginTransaction(IsolationLevel.ReadCommitted);
}
if (parameterValues != null)
{
AttachParameters(cmd, parameterValues);
}
return cmd.ExecuteOracleScalar();
}
catch (System.Exception e)
{
if (cmd.Transaction != null)
{
cmd.Transaction.Rollback();
LogHelper.WriteLog("MsOracle.ExecuteScalarByTransaction(OracleConnection connObjection, string sqlString, params OracleParameter[] parameterValues)", "回滚事务", e);
}
throw new System.Exception(e.Message);
}
}