How to insert record using LINQ programmtically?

Posted by SheoNarayan under LINQ category on | Views : 18462
Write following code.

// LINQ object
DataUsersClassesDataContext dataUsers = new DataUsersClassesDataContext();
// The database table object inside LINQ, instantiate it
ThisUser user = new ThisUser();
// set all properties, these are nothing but fields your database tables
user.Active = active;
user.Name = "My Name";
user.Role = role;
dataUsers.Users.InsertOnSubmit(user); // still not inserted into database, just added into the LINQ Database object
dataUsers.SubmitChanges(); //make change to the database now

Comments or Responses

Posted by: Poster on: 10/16/2008 Level:Starter | Status: [Member]
Thanks sir, it was helpful.

Login to post response