views:

42

answers:

1

I have an .mdf file which I'm trying to add a record to, using linq in C#. My code is:

dbDataContext context = new dbDataContext();
book b = new book();
b.title = "Test Book";
b.isbn = "123789";
context.books.InsertOnSubmit(b);
context.SubmitChanges();

When this code runs, the record is not inserted, and I get no error messages. If I use the database explorer to add a record with the selfsame data, it works.

What's going on?

+1  A: 

Generally when this happens it is indicative of the changes going to the incorrect database. Check your connection settings in your dbml. To test out the theory, try adding a record or two programmatically and if you have an identity field in that database, after context.SubmitChanges() check what the value of b.Id is (where Id is equal to your IDENTITY column). If it has a value, then you most definitely have a connection issue & you should check for another database. Pay particular attention to your bin/debug directory.

coderpros
Sincere thanks for your help. I was being a douche and letting c# copy my db to the bin directory at run time, so I was basically working off a temporary copy.
Matt
haha! No worries, man. It happens to me all of the time. I've been working with the M$ Sync framework lately and had something very similar happen to me yesterday. Kept me busy for 4 hours. Lemme know if they're hiring when ya get that food service job! ;)
coderpros