CMSDataContext db = new CMSDataContext(); var user = db.Users.First(u => u.Id == 1); user.Name = "John Doe"; //changing the existing user's name db.SubmitChanges(); //submitting the change to database
CMSDataContext db = new CMSDataContext(); var newUser = new User { Name = "Jane Doe", Email = "[email protected]", Password = "password123" }; db.Users.InsertOnSubmit(newUser); //adding a new user to the database db.SubmitChanges(); //submitting the new user to databaseIn this example, we are creating a new user object and adding it to the database using InsertOnSubmit method. Then we use the SubmitChanges method to save the new user to the database. In both examples, we use the SubmitChanges method to save changes made to the database. The CMSDataContext class belongs to the CMSData package library.