Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a record to a database with LINQ?

I have been utilizing Scott Gu's tutorials on LINQ to SQL to try to learn some LINQ. I have been able to view, retrieve, and update records but I am unable to write new records into the database (MSSQL). Scott starts getting into inserting rows in the fourth section of the set of tutorials. As you can see on that page (or may already know), in order to add a record you must do the following (VB.NET):

Dim db as New LINQtoSQLDataContext

Dim oArticle as New article // table name
oArticle.Body = "Some Text"
oArticle.Title = "Some Title"
oArticle.Author = "Some Author"

db.articles.Add(oArticle) // this is the line that does not work.

Visual Studio 2008 returns me "'add' is not a member of 'System.Data.Linq.Table(Of article)".

Can anyone give me a push in the right direction? Thanks!

like image 479
Anders Avatar asked Dec 30 '22 04:12

Anders


1 Answers

db.articles.InsertOnSubmit(oArticle)
db.SubmitChanges()
like image 134
John Boker Avatar answered Jan 08 '23 15:01

John Boker