Alex
Alex

Reputation: 36101

ASP.NET LINQ to SQL SubmitChanges() doesn't update the database

In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I call the SubmitChanges method of the DataContext class, nothing updates in the database. It's weird because everything works fine with my first project.

I'm using a remote database created in Sql Server Management Studio, I tried doing some queries there and in Visual Studio 2010 (where I have the connection to the database), they all work.

Where might the problem be hidden?

DBDataContext DB = new DBDataContext();
var myuser = DB.Users.Single(u => u.ID == id);
myuser.Age = 45;
DB.SubmitChanges();

SOLUTION

This is embarrassing :D Indeed I didn't have a primary key. Now it works!

Thanks to everybody!

Upvotes: 2

Views: 3255

Answers (4)

wotu
wotu

Reputation: 54

Table , KEY :)::):)

Insert KEY in TABLE !!!!!

Upvotes: 3

roufamatic
roufamatic

Reputation: 18485

I'd check your connection string. You might not be connecting to the database you think you're connecting to.

Upvotes: 0

Greg Roberts
Greg Roberts

Reputation: 2562

Is it possible that the entities you are modifying are not connected to the DataContext? This would prevent them from causing updates to your database.

Upvotes: 0

eKek0
eKek0

Reputation: 23289

Maybe there isn't anything to submit to the database? SubmitChanges() only will submit modified or new data, if you don't have either, then it will no have any persitent effect.

You may want to read ScottGu's series on Linq to understand a bit more about Linq, or could want to by a book like Linq in action.

Upvotes: 0

Related Questions