"crud operation without entity framework in mvc" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "crud operation without entity framework in mvc" answered properly. Developers are finding an appropriate answer about crud operation without entity framework in mvc related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like crud operation without entity framework in mvc. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on crud operation without entity framework in mvc.
crud operation without entity framework in mvc
using System.Web.Mvc;using CRUDinMVC.Models; namespace CRUDinMVC.Controllers{ public class StudentController : Controller { // 1. *************RETRIEVE ALL STUDENT DETAILS ****************** // GET: Student public ActionResult Index() { StudentDBHandle dbhandle = new StudentDBHandle(); ModelState.Clear(); return View(dbhandle.GetStudent()); } // 2. *************ADD NEW STUDENT ****************** // GET: Student/Create public ActionResult Create() { return View(); } // POST: Student/Create [HttpPost] public ActionResult Create(StudentModel smodel) { try { if (ModelState.IsValid) { StudentDBHandle sdb = new StudentDBHandle(); if (sdb.AddStudent(smodel)) { ViewBag.Message = "Student Details Added Successfully"; ModelState.Clear(); } } return View(); } catch { return View(); } } // 3. ************* EDIT STUDENT DETAILS ****************** // GET: Student/Edit/5 public ActionResult Edit(int id) { StudentDBHandle sdb = new StudentDBHandle(); return View(sdb.GetStudent().Find(smodel => smodel.Id == id)); } // POST: Student/Edit/5 [HttpPost] public ActionResult Edit(int id, StudentModel smodel) { try { StudentDBHandle sdb = new StudentDBHandle(); sdb.UpdateDetails(smodel); return RedirectToAction("Index"); } catch { return View(); } } // 4. ************* DELETE STUDENT DETAILS ****************** // GET: Student/Delete/5 public ActionResult Delete(int id) { try { StudentDBHandle sdb = new StudentDBHandle(); if (sdb.DeleteStudent(id)) { ViewBag.AlertMsg = "Student Deleted Successfully"; } return RedirectToAction("Index"); } catch { return View(); } } }}
Source: www.completecsharptutorial.com
crud operation without entity framework in mvc
using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Configuration; namespace CRUDinMVC.Models{ public class StudentDBHandle { private SqlConnection con; private void connection() { string constring = ConfigurationManager.ConnectionStrings["studentconn"].ToString(); con = new SqlConnection(constring); } // **************** ADD NEW STUDENT ********************* public bool AddStudent(StudentModel smodel) { connection(); SqlCommand cmd = new SqlCommand("AddNewStudent", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Name", smodel.Name); cmd.Parameters.AddWithValue("@City", smodel.City); cmd.Parameters.AddWithValue("@Address", smodel.Address); con.Open(); int i = cmd.ExecuteNonQuery(); con.Close(); if (i >= 1) return true; else return false; } // ********** VIEW STUDENT DETAILS ******************** public List<StudentModel> GetStudent() { connection(); List<StudentModel> studentlist = new List<StudentModel>(); SqlCommand cmd = new SqlCommand("GetStudentDetails", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sd = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); con.Open(); sd.Fill(dt); con.Close(); foreach(DataRow dr in dt.Rows) { studentlist.Add( new StudentModel { Id = Convert.ToInt32(dr["Id"]), Name = Convert.ToString(dr["Name"]), City = Convert.ToString(dr["City"]), Address = Convert.ToString(dr["Address"]) }); } return studentlist; } // ***************** UPDATE STUDENT DETAILS ********************* public bool UpdateDetails(StudentModel smodel) { connection(); SqlCommand cmd = new SqlCommand("UpdateStudentDetails", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StdId", smodel.Id); cmd.Parameters.AddWithValue("@Name", smodel.Name); cmd.Parameters.AddWithValue("@City", smodel.City); cmd.Parameters.AddWithValue("@Address", smodel.Address); con.Open(); int i = cmd.ExecuteNonQuery(); con.Close(); if (i >= 1) return true; else return false; } // ********************** DELETE STUDENT DETAILS ******************* public bool DeleteStudent(int id) { connection(); SqlCommand cmd = new SqlCommand("DeleteStudent", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@StdId", id); con.Open(); int i = cmd.ExecuteNonQuery(); con.Close(); if (i >= 1) return true; else return false; } }}
Source: www.completecsharptutorial.com
crud operation without entity framework in mvc
<connectionStrings> <add name="StudentConn" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;Pooling=False"/> </connectionStrings>
Source: www.completecsharptutorial.com
crud operation without entity framework in mvc
Create procedure [dbo].[DeleteStudent] ( @StdId int ) as begin Delete from StudentReg where Id=@StdId End
Source: www.completecsharptutorial.com
crud operation without entity framework in mvc
Create procedure [dbo].[UpdateStudentDetails] ( @StdId int, @Name nvarchar (50), @City nvarchar (50), @Address nvarchar (100) ) as begin Update StudentReg set Name=@Name, City=@City, Address=@Address where Id=@StdId End
Source: www.completecsharptutorial.com
crud operation without entity framework in mvc
Create Procedure [dbo].[GetStudentDetails] as begin select * from StudentRegEnd
Source: www.completecsharptutorial.com
crud operation without entity framework in mvc
Create procedure [dbo].[AddNewStudent] ( @Name nvarchar (50), @City nvarchar (50), @Address nvarchar (100) ) as begin Insert into StudentReg values(@Name,@City,@Address) End
Source: www.completecsharptutorial.com
All those coders who are working on the Whatever based application and are stuck on crud operation without entity framework in mvc can get a collection of related answers to their query. Programmers need to enter their query on crud operation without entity framework in mvc related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about crud operation without entity framework in mvc for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of crud operation without entity framework in mvc while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "crud operation without entity framework in mvc". Visit this developer's friendly online web community, CodeProZone, and get your queries like crud operation without entity framework in mvc resolved professionally and stay updated to the latest Whatever updates.