Last post Apr 23, 2018 06:13 PM by DA924
Apr 23, 2018 03:39 PM|Kaseikei|LINK
I have developed a MVC asp.net application to a point of satisfaction. Currently i'm populating a list and passing it to a controller to perform different tasks and generate views. However i recently received the oracle connection information required to
make the application live with data. I have no clue how to even approach this and the help online is very slim. I have never posted in a forum before so this says a lot. If it helps i'm using VS 2017, Oracle is 12c, i have the host name SID, user Pass, and
The main goal is to take data from a table in the DB, and feed it to my controller. Any help at all is greatly appreciated.
Apr 23, 2018 05:02 PM|Khanna Gaurav|LINK
Refer following links
Apr 23, 2018 06:13 PM|DA924|LINK
It doesn't make any difference if ASP.NET MVC, ASP.NET Web forms or Windows form application is being used. And it doesn't matter what version of Visual Studio that is being used either.
How you use Oracle is being explained in the link.
The above link also talks about the Oracle Data Provider, and in your case, you will have to install the 12c driver.
You don't want to use datasets, datatables and adapters, but rather, you'll want to use Oracle Command objects with either inline parametrized p-sql or parametrized Oracle package for CRUD.
You want to use custom object like a DTO with the DTO being loaded into a List <T> and returned from the reader loop.
Dim oradb As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=" _
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=ORASRVR)(PORT=1521)))" _
+ "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));" _
+ "User Id=hr;Password=hr;"
Dim conn As New OracleConnection(oradb) ' Visual Basic
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = _
"select department_id, department_name, location_id from departments" ' VB
cmd.CommandType = CommandType.Text
Dim dr As OracleDataReader = cmd.ExecuteReader()
ListBox1.Items.Add("The " + dr.Item("department_name") + _
" department is in " + dr.Item("location_id").ToString())
Modify your C# code to look like this:
string oradb = "Data Source=(DESCRIPTION=(ADDRESS_LIST="
+ "User Id=hr;Password=hr;";
OracleConnection conn = new OracleConnection(oradb); // C#
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select department_id, department_name, location_id from departments.168";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
listBox1.Items.Add("The " + dr["department_name"].ToString() +
" department is in " + dr["location_id"].ToString());