Linq to SQL SubmitChanges() not working if textbox modified by listbox
In a simple test form, I have a listbox and a textbox. The form is bound to a datacontext, which has a single table. The listbox has two items, and is not bound. The textbox is bound to the datacontext.
When I select an item from the listbox, the following code runs:
txtTest.Text = lstTest.SelectedItems(0).ToString
Then when I push my Save button, the following code runs:
Me.TextDC.SubmitChanges()
But - the database field which the textbox is bound to is NOT updated.
If I manually type in a value into the textbox and then push the Save button, the database field IS updated.
I've been trying to solve this on and off for several days, and I finally made this very simple text form to confirm or deny what was happening. No errors occur.
So, for some reason SubmitChanges() does not recog开发者_如何学Cnize that the textbox needs to be updated if it's .Text property has been updated from the listbox, but does recognize that it needs to be updated if I manually type in a value.
Any thoughts?
Solved! Somehow, I don't know how exactly, the connection string to SQL Server in the dbml file and the connection string in the application settings file were slightly different. I made absolutely sure they were both pointing to the same sql server database, and all works correctly now.
精彩评论