I have a editable GridView on my webforms page. Users can enter records and after hitting submit using LINQ I am inserting the records to the database. It is working absolutely fine.
I am not able to figure out how to update the records. I am populating the records in the GridView once the user hits the submit button, I need to update the existing records.
How can this be done?
Dim db as new empDBDataContext
Dim rw As GridViewRow
Dim emp as new employee
emp.name="test"
emp.city="NYC"
emp.age=40
For each rw in GridView1.Rows
Dim cert as new certifications
cert.Name=CType(rw.FindControl("lblCert"), TextBox).Text
cert.score=CType(rw.FindControl("lblScore"), TextBox).Text
emp.cert.add(cert)
Next
db.emp.insertonsubmit(emp)
db.submitChanges()
You can use your unique identifier for certifications to select the rows from the database (I used
lblIdas the control name). Then, set the properties to the updated values. It’s very similar to what you’re doing for the insert. Please excuse my VB syntax ignorance…