views:

275

answers:

4

I am really confused about why an update is not taking place. This is very simple:

    int goodID = 100;

    DataContext db = new DataContext();

    Schedule schedule = db.Schedules.Single(s => s.ID == goodID);

    // this wont persist - WHY NOT?!
    schedule.Email = txtEmail.Text;

    // this does persist
    schedule.NumberCourses = 5;

    db.SubmitChanges();

I can't understand why the field, Email, isn't getting the value from the textbox. What can I check?

EDIT

I have set a breakpoint and checked the value after assignment. It assigns the textbox value but still no update.

+1  A: 

Set a breakpoint and check the value of schedule.Email before and after that line. Also, use the immediate window to check txtEmail.Txt to see if it actually contains data.

Tell us what you find.

JoshJordan
I tried all of that before posting. It looks good.
Ronnie Overby
Can you change schedule.Email with a manual SQL query? Profile the LTS query and use that parameterized query manually as well. Again, tell us what happens :)
JoshJordan
+2  A: 

Check what changes will be submitted to the datacontext.

Add a breakpoint just before the db.SubmitChanges() line gets executed and add the following Watch:

db.GetChangeSet();

In the Watch (or Quick Watch) window you'll be able to see which changes are being submitted.

CMS
+1  A: 

Does that dbml match the database table? If it doesn't match the database, you can get wierd things. Try reimporting it.

asp316
A: 

I am an idiot. It's fixed. Votes for everyone. Instead of checking in the database, like a normal person would, I was just looking on the webform after refreshing the page. I wasn't initializing the textbox with the value from the db. So the update was happening. See? I told you I was an idiot.

Ronnie Overby
Ronnie, can you share with us what the problem was? Whether you think its dumb or not, you're very unlikely to be the only one to ever have the problem and someone may be able to learn from it :)
JoshJordan