Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have one question How to create Oracle connection with MVC not using Entity Framework using visual studio 2019 i have as example connection to SQL server as mvc using ADO.NET and I want do the same with oracle code below: and i want to make the same thing but for oracle databes i have new user in oracle named=c##admin password=tiger

**My controller:
Ausing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.SqlClient;
using System.Data;
using mvcmytask.Models;
namespace mvcmytask.Controllers
{
    public class TaskController : Controller
    {
        // GET: Task
        string connectionstring = @"Data Source = (local)SQLEXPRESS; Initial Catalog = Todolist; Integrated Security=True";
        [HttpGet]
        
        public ActionResult Index()
        {
            DataTable dtbltask = new DataTable();
            using (SqlConnection SqlCon = new SqlConnection(connectionstring))
            {
                SqlCon.Open();
                SqlDataAdapter SqlDa = new SqlDataAdapter("select * from dotable", SqlCon);
                SqlDa.Fill(dtbltask);
            }
            return View(dtbltask);
        }
        // GET: Task/Create
        [HttpGet]
        public ActionResult Create()
        {
            return View(new Class1());
        }
        // POST: Task/Create
        [HttpPost]
        public ActionResult Create(Class1 class1)
        {
            using (SqlConnection SqlCon = new SqlConnection(connectionstring))
            {
                SqlCon.Open();
                string query = "insert into dotable values (@Task_name,@Task_description,@Task_status)";
                SqlCommand Sqlcmd = new SqlCommand(query, SqlCon);
                Sqlcmd.Parameters.AddWithValue("@Task_name", class1.Task_name);
                Sqlcmd.Parameters.AddWithValue("@Task_description", class1.Task_description);
                Sqlcmd.Parameters.AddWithValue("@Task_status", class1.Task_status);
                Sqlcmd.ExecuteNonQuery();
            }
            return RedirectToAction("Index");
        
        }
        // GET: Task/Edit/5
        public ActionResult Edit(int id)
        {
            Class1 class1 = new Class1();
            DataTable dtbltask = new DataTable();
            using (SqlConnection SqlCon = new SqlConnection(connectionstring))
            {
                SqlCon.Open();
                string query = "Select * from dotable where task_id=@Task_id";
                SqlDataAdapter SqlDa = new SqlDataAdapter(query, SqlCon);
                SqlDa.SelectCommand.Parameters.AddWithValue("@Task_id", id);
                SqlDa.Fill(dtbltask);
            }
            if (dtbltask.Rows.Count == 1)
            {
                class1.Task_id = Convert.ToInt32(dtbltask.Rows[0][0].ToString());
                class1.Task_name = (dtbltask.Rows[0][1].ToString());
                class1.Task_description = (dtbltask.Rows[0][2].ToString());
                class1.Task_status = (dtbltask.Rows[0][3].ToString());
                return View(class1);
            }
            return RedirectToAction("Index");
        }
        // POST: Task/Edit/5
        [HttpPost]
        public ActionResult Edit(Class1 class1)
        {
            using (SqlConnection SqlCon = new SqlConnection(connectionstring))
            {
                SqlCon.Open();
                string query = "My_Updating";
                /* can use sql_query in line or Stored Procedure
                string query = "update dotable set task_name=@Task_name,task_description=@Task_description,task_status=@Task_status where task_id=@Task_id";*/
                SqlCommand Sqlcmd = new SqlCommand(query, SqlCon);
                //optional command use with stored procedure only
                Sqlcmd.CommandType = CommandType.StoredProcedure;
                Sqlcmd.Parameters.AddWithValue("@Task_id", class1.Task_id);
                Sqlcmd.Parameters.AddWithValue("@Task_name", class1.Task_name);
                Sqlcmd.Parameters.AddWithValue("@Task_description", class1.Task_description);
                Sqlcmd.Parameters.AddWithValue("@Task_status", class1.Task_status);
                Sqlcmd.ExecuteNonQuery();
            }
            return RedirectToAction("Index");
        }
        // GET: Task/Delete/5
        public ActionResult Delete(int id)
        {
            using (SqlConnection SqlCon = new SqlConnection(connectionstring))
            {
                SqlCon.Open();
                string query = "delete from dotable where task_id=@Task_id";
                SqlCommand Sqlcmd = new SqlCommand(query, SqlCon);
                Sqlcmd.Parameters.AddWithValue("@Task_id", id);
              
                Sqlcmd.ExecuteNonQuery();
            }
            return RedirectToAction("Index");
        }
    }
}**

my view for "Index":

**@model System.Data.DataTable
@{
    ViewBag.Title = "Index";
}
<table class="table table-bordered table-striped">
    <tr>
        <th>Task name </th>
        <th>Task description </th>
        <th>Task status </th>
        <th></th>
       
    </tr>
    @for (int i = 0; i < Model.Rows.Count; i++)
    {
<tr>
    <td>@Model.Rows[i][1]</td>
    <td>@Model.Rows[i][2]</td>
    <td>@Model.Rows[i][3]</td>
    <td>
        <a href="@Url.Action("Edit","Task",new {id=@Model.Rows[i][0] })">Edit</a>
        <a href="@Url.Action("Delete","Task",new {id=@Model.Rows[i][0] })">Delete</a>
    </td>
    
</tr>
    }
</table>
<a href="@Url.Action("Create","Task")">Add Task</a>**


 
question from:https://stackoverflow.com/questions/65934487/how-to-create-oracle-connection-with-mvc-not-using-entity-framework

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
71 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...