Return to Snippet

Revision: 65849
at January 29, 2014 08:29 by heathbo


Initial Code
using Oracle.DataAccess.Client;


private const string SqlInsertStatusCode = @"INSERT INTO STATUS_CODES(ID, STATUS_CODE, GROUP_CODE, DESCRIPTION, RANK)													VALUES(STATUS_CODE_SEQ1.NEXTVAL, :STATUSCODE, :GROUPCODE, :DESCR, :STATUSCODE_RANK)
RETURNING ID INTO :OUTPUT_ID";



public int AddStatusCode(StatusCode statusCode)
{
	OracleParameter[] parameters = 
	{
		CreateOracleParameter("OUTPUT_ID", null, OracleDbType.Int32,ParameterDirection.Output),
		CreateOracleParameter("DESCR",SafeDbConvert<string>(statusCode.Description),OracleDbType.Char),
		CreateOracleParameter("GROUPCODE", SafeDbConvert<string>(statusCode.GroupCode),OracleDbType.Char),
		CreateOracleParameter("STATUSCODE_RANK", SafeDbConvert<int>(statusCode.Rank),OracleDbType.Int32),
		CreateOracleParameter("STATUSCODE", SafeDbConvert<int>(statusCode.Status_Code), OracleDbType.Int32),
	};

	ExecuteNonQuery(SqlInsertStatusCode, parameters);

	return int.Parse(parameters[0].Value.ToString());
}

Initial URL

                                

Initial Description
How to set add a record in an Oracle table and return a value in the same query using C#.

Returning ID INTO : OUTPUT_ID is referring to returning the value found in the ID field in the SQL table to the OUTPUT_ID parameter set in the AddStatusCode method.

Initial Title
Set and return data from Oracle using C#

Initial Tags

                                

Initial Language
C#