ADO.NET C# and Oracle Database
public static void GetStudentFromBanner(String studentId)
{
String connectionString = ConfigurationManager.ConnectionStrings["BannerDB"].ConnectionString;
try
{
String firstName = string.Empty;
String lastName = string.Empty;
String dob = string.Empty;
String email = string.Empty;
String holdCode = string.Empty;
using (OracleConnection con = new OracleConnection(connectionString))
{
using (OracleCommand cmd = new OracleCommand("QNOMY.P_NCC_ST_GET_STUDENT_INFO", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("p_id", OracleDbType.Varchar2).Value = studentId;
OracleParameter firstNameParam = new OracleParameter("p_first_name", OracleDbType.Varchar2, 30);
firstNameParam.Direction = ParameterDirection.Output;
cmd.Parameters.Add(firstNameParam);
OracleParameter lastNameParam = new OracleParameter("p_last_name", OracleDbType.Varchar2, 30);
lastNameParam.Direction = ParameterDirection.Output;
cmd.Parameters.Add(lastNameParam);
OracleParameter dobParam = new OracleParameter("p_dob", OracleDbType.Varchar2, 10);
dobParam.Direction = ParameterDirection.Output;
cmd.Parameters.Add(dobParam);
OracleParameter emailParam = new OracleParameter("p_email", OracleDbType.Varchar2, 30);
emailParam.Direction = ParameterDirection.Output;
cmd.Parameters.Add(emailParam);
OracleParameter holdCodeParam = new OracleParameter("p_holds", OracleDbType.Varchar2, 30);
holdCodeParam.Direction = ParameterDirection.Output;
cmd.Parameters.Add(holdCodeParam);
con.Open();
cmd.ExecuteNonQuery();
OracleString firstNameOracle = (OracleString)firstNameParam.Value;
if (!firstNameOracle.IsNull)
{
firstName = Convert.ToString(firstNameParam.Value);
}
OracleString lastNameOracle = (OracleString)lastNameParam.Value;
if (!lastNameOracle.IsNull)
{
lastName = Convert.ToString(lastNameParam.Value);
}
OracleString dobOracle = (OracleString)dobParam.Value;
if (!dobOracle.IsNull)
{
dob = Convert.ToString(dobParam.Value);
}
OracleString emailOracle = (OracleString)emailParam.Value;
if (!emailOracle.IsNull)
{
email = Convert.ToString(emailParam.Value);
}
OracleString holdCodeOracle = (OracleString)holdCodeParam.Value;
if (!holdCodeOracle.IsNull)
{
holdCode = Convert.ToString(holdCodeParam.Value);
}
}
}
Console.WriteLine("Result from GetStudentFromBanner(String studentId):");
Console.WriteLine("Student Id: " + studentId);
Console.WriteLine("First Name: " + firstName);
Console.WriteLine("Last Name: " + lastName);
Console.WriteLine("DOB: " + dob);
Console.WriteLine("Email: " + email);
Console.WriteLine("Hold Code: " + holdCode);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.Read();
}
}