开发者

(Asp.net) I can't Insert a new row using Linq to Sql

开发者 https://www.devze.com 2022-12-09 23:07 出处:网络
So I\'m trying to do a simple insert using Linq but i\'m running into trouble. code: TestDatacontext db = new TestDatacontext ();

So I'm trying to do a simple insert using Linq but i'm running into trouble.

code:

        TestDatacontext db = new TestDatacontext ();
        Comment com = new Comment();
        com.UserID = userId;
        com.TaskID = taskId;
        com.Description = Server.HtmlEncode(txtComments.Text);开发者_JS百科
        com.DateCreated = DateTime.Now;   

Now at this point, from what I've read I should be able to do this:

db.Comments.Add(com);
db.Submitchanges();

However, when I write db.Comments. [There is no Add method]

So...how do I insert?


You're looking for db.Comments.InsertOnSubmit(com);

0

精彩评论

暂无评论...
验证码 换一张
取 消