I am trying to update a table using LinQ. Though records are getting inserted, for some reason they are not getting updated.
what can be possible problem
Dim db as new empDataContext
Dim emptable as new employee
if update then
emptable=GetEmp(txtempID.Text)
emptable.Name="Test"
emptable.Age=11
emptable.City="NYC"
else
emptable.Name="Test"
emptable.Age=11
emptable.City="NYC"
emtable.deptID=10
db.employee.InsertOnSubmit(emptable)
end if
db.SubmitChanges()
Judging just from what I can see here, I’m guessing your
GetEmpmethod is using a different data context to retreive the data than the one you’re using to save it back to the DB.When using LINQ to SQL, the context is what tracks the changes to the tables. If you’re not careful and mix Contexts by accident, you can get strange behaviors like this.
You can test by chaging:
to
If you find that the context is the issue, just modify your
GetEmpmethod to accept the context as a parameter rather than creating a new one itself.