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#:
<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>
Install the Oracle.ManagedDataAccess NuGet package in your project.
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();
}
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();
return Json(new { value }, JsonRequestBehavior.AllowGet);