Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 486.5k

Save data in DB in asp.net mvc without entity framework?

Mar 20 2020 3:05 AM
Hi Team
 
I want to find an example as to how to save record from a form to database table. Im not using entity framework, i have connectionString on web.config. Please share any useful relevant example to my requirement mates.  

Answers (3)

0
Ravi Patel

Ravi Patel

  • 271
  • 6.8k
  • 1.4m
Mar 20 2020 4:02 AM
Hi,
 
 refer this 
 
  • https://www.c-sharpcorner.com/UploadFile/0c1bb2/insertupdatedelete-in-Asp-Net-mvc-5-using-ado-net/ 
  • https://www.c-sharpcorner.com/UploadFile/francissvk/crud-operations-in-Asp-Net-mvc-using-ado-net/ 
0
Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 486.5k
Mar 20 2020 3:19 AM
Here what i want to do exactly, i am using connection string to attempt this and have this logic below. Somehow i am beginning to get stuck in the middle.
  1. private SqlConnection con;  
  2.   
  3.   
  4.    // private method for connection.  
  5.         private void connection()  
  6.         {  
  7.             string constr = ConfigurationManager.ConnectionStrings["DefConnection"].ToString();  
  8.             con = new SqlConnection(constr);  
  9.         }  
  10.   
  11.   
  12.   
  13.         //GET:/Manage/AddNewDetails.  
  14.         public ActionResult AddNewDetails()  
  15.         {  
  16.             return View();  
  17.         }  
  18.           
  19.   
  20.         //POST://Manage to add-new-details.  
  21.         [HttpPost]  
  22.         public ActionResult AdAddNewDetails(EditTrainingRegFormViewModel model)  
  23.         {  
  24.            // logic here.  
  25.   
  26.   
  27.             return View();  
  28.         }  
  29.   
  30. // Model class  
  31. public class EditTrainingRegFormViewModel  
  32.     {  
  33.         public string Title { getset; }  
  34.   
  35.         public string FirstName { getset; }  
  36.   
  37.         public string LastName { getset; }  
  38.   
  39.         public string Position { getset; }  
  40.   
  41.         public string Company { getset; }  
  42.   
  43.         public string Address { getset; }  
  44.   
  45.         [Display(Name = "Choose country")]  
  46.         public int? SelectedCountryId { getset; }  
  47.   
  48.        [Required]  
  49.        [RegularExpression(@"^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$")]  
  50.        [Display(Name= "Postal/Zip Code")]  
  51.         public string Code { getset; }  
  52.   
  53.         [DataType(DataType.Text)]  
  54.         [Required(ErrorMessage = "This field is required")]  
  55.         public string City { getset; }  
  56.   
  57.         public string State { getset; }  
  58.   
  59.         
  60.         [Required(ErrorMessage = "This field is required")]  
  61.         public string Cell_Number { getset; }  
  62.   
  63.         public List<CheckBox> Dietary_requirement = new List<CheckBox>();  
  64.   
  65.         [Required(ErrorMessage ="This field is required")]  
  66.         [EmailAddress(ErrorMessage ="Enter correct email")]  
  67.         [RegularExpression(@"^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$")]  
  68.         public string Email { getset; }  
  69.   
  70.         public int Country_Id { getset; }  
  71.   
  72.         public string Country_Name { getset; }  
  73.   
  74.   
  75. }  
0
Mario Scheeren

Mario Scheeren

  • 550
  • 2.1k
  • 35.9k
Mar 20 2020 3:12 AM
Take a look at this here: https://dapper-tutorial.net/dapper