How to insert data in LINQ to SQL

Raja
Posted by Raja under LINQ category on | Points: 40 | Views : 3767
Below is the code snippet to insert record using LINQ to SQL into the database.

Assuming dContext is your data context, MyTable is the database table mapped in the context.

using (dContext db = new dContext())
{
MyTable w = new MyTable ()
{
MyName = txtName.Text,
MyAddress = txtAddress.Text
};

db.MyTable.InsertOnSubmit(w);
db.SubmitChanges();
}


Thanks

Comments or Responses

Login to post response