我一直在使用Scott Gu's tutorials on LINQ to SQL尝试学习一些LINQ。我已经能够查看,检索和更新记录,但是无法将新记录写入数据库(MSSQL)。 Scott开始在这套教程的fourth section中插入行。如您在该页面上看到的(或可能已经知道)那样,为了添加记录,您必须执行以下操作(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向我返回“
'add' is not a member of 'System.Data.Linq.Table(Of article)
”。谁能给我正确的方向推动?谢谢!
最佳答案
db.articles.InsertOnSubmit(oArticle)
db.SubmitChanges()