Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here are the steps to integrate a value from an Oracle database into an MVC Bootstrap project using .NET 5 and C#:

  1. Create an Oracle connection string in your web.config or appsettings.json file. Here's an example:
<connectionStrings>
  <add name="OracleConnection" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE))); User Id=your_user_id; Password=your_password;" providerName="Oracle.ManagedDataAccess.Client" />
</connectionStrings>
  1. Install the Oracle.ManagedDataAccess NuGet package in your project.

  2. In your controller, create an instance of the OracleConnection class and open the connection using the connection string.

using Oracle.ManagedDataAccess.Client;

...

var connectionString = ConfigurationManager.ConnectionStrings["OracleConnection"].ConnectionString;

using (var connection = new OracleConnection(connectionString))
{
    connection.Open();
}
  1. Prepare an OracleCommand object with your SQL query and execute the command to retrieve the value from the database.
var command = connection.CreateCommand();
command.CommandText = "SELECT value FROM your_table WHERE id = :id";
command.Parameters.Add("id", OracleDbType.Int32).Value = id;

var value = command.ExecuteScalar();
  1. Pass the value to your view or return it as JSON to an AJAX call.
return Json(new { value }, JsonRequestBehavior.AllowGet);