I have a movie database where I'm trying to save a genre. I have the
same project in winforms and there the code works, so it's probably something simple
that I missed.
Anyways, here is the
code:
MovieCollectionEntities db
= new MovieCollectionEntities();
Genre g = new Genre();
g.GenreName = TextBoxGenresAdd.Text;
db.Genres.Add(g);
db.SaveChanges();
The
error message I get
is:
System.NullReferenceException
was unhandled by user code
HResult=-2147467261
Message=Object
reference not set to an instance of an
object.
edit:
/>Worth mentioning is probably that I'm using master paging and the code is from the
AddGenre.aspx.
edit2: Complete answer can be
found @ href="https://stackoverflow.com/questions/17136455/nullreferenceexception-in-dbcontext-savechanges">NullReferenceException
in DbContext.saveChanges()
@Abhinav
linked to the correct page. The problem was that the aspx pages had the same names as
the entity names which made the program crash.
No comments:
Post a Comment