Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • LINQ Insert in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 190
    Comment on it

    In MVC while performing the interaction with the database we can use Language Integrated Query for easier manipulation of the data in the data source.

     

     

     

     

    We can use it very easily by first creating the Data Context for the project then it will be used for that table which we want to manipulate.

     

     

     

     

    Then after this we will create the method in which the insertion is being performed.

     

     

    EmployeeDetail empdet = new EmployeeDetail();
                    empdet.EmpFirstName = EmpMod.FirstName;
                    empdet.EmpMiddleName = EmpMod.MiddleName;
                    empdet.EmpLastName = EmpMod.LastName;
                    DataContextObj.EmployeeDetails.InsertOnSubmit(empdet);
                    DataContextObj.SubmitChanges();

     

     

    This will insert the details to the database according to your model.

     

    public enum getstatus
        {
            success, failure
        }
        public class EmployeeModel
        {
    
            public int EmpId { get; set; }
            [Required(ErrorMessage = "First Name is required")]
            public string FirstName { get; set; }
            public string MiddleName { get; set; }
            [Required(ErrorMessage = "Last Name is required")]
            public string LastName { get; set; }
            [Required(ErrorMessage = "PhoneNo is required")]
            public string PhoneNo { get; set; }
            public string Address { get; set; }
            public getstatus Status { get; set; }
            public string msg { get; set; }
        }

     

     

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: