Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add, update and delete the records into the database using linq

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 489
    Comment on it

    UserEntities objUserEntities= new UserEntities();/*Create object of user entity

    /* Add records into the database */

    public void AddUser(User objUser)
    {
    objUserEntities.AddToUsers(objUser); /*Linq has its own function to insert the record Add()*/
    objUserEntities.SaveChanges();/*This function save the changes to the database*/
    }

    /* Update the records into the database */

    public void EditRecords(Details1 objDetail)
    {
    Details1 Details= (from o in objUserEntities.Details1 where o.ID==objDetail.ID select o).SingleOrDefault(); /*Get the records which we have to edit*/
    /*Edit the records*/
    Details.Name=objDetail.Name;
    Details.Phoneno=objDetail.Phoneno;
    Details.Address=objDetail.Address;
    objUserEntities.SaveChanges(); /*Save the changes to the database*/
    }

    /*Delete records into the database */

    public List DeleteDetails(int id)
    {
    Details1 objDetails= (from o in objUserEntities.Details1 where o.ID==id select o).SingleOrDefault();/*Get the records which we have to delete*/
    objUserEntities.DeleteObject(objDetails);/*Linq has its own function to delete the records DeleteObject()*/
    objUserEntities.SaveChanges();/*Save the records into the database*/
    }

 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: