Inserting records using LinqToSql

I wasn’t able to find any good examples on Google (they were all for old CTPs).
So to all that this may help, this is how you can insert a record into SQL using Linq (LinqToSQL).

NorthWindDataContext db = new NorthWindDataContext();
Product prod = new Product();
prod.ProductName = "The Dave Special";
prod.CategoryID = 1;
prod.UnitPrice = 24;
prod.UnitsInStock = 1;

//This is the line I kept missing
db.Peoples.InsertOnSubmit(prod);

db.SubmitChanges();

Shoutout to Jordan for helping me with this

0 Responses to “Inserting records using LinqToSql”


  1. No Comments

Leave a Reply