bound Datagrid update

NeilA

Member
Joined
Aug 31, 2006
Messages
14
Programming Experience
1-3
I have a datagrid on my form which is populated using a datatable. The datatable is populated from a data adapter. What I want to do is be able to detect which record the user has clicked in the datagrid and then subsequently update the appropriate record in the database with a new value.

What is the most easiest and efficient way to do this?

Thanks

PS. This is my first post :)
 
You probably can do it that way, but the dataadapter is a clever little component and when you call it's update method combined with an appropriate SQL statement it will send the appropriate changes to the database.
When your user has finsihed editing the datagrid you can use the GetChanges method of the dataset/datatable to return a dataset/datatable to return a new dataset/datatable with all of the rows that have been modified/deleted/inserted
 
If you really want to go your route, try this


VB.NET:
          For Each Row As DataGridViewRow In DataGridView.Rows
               If Row.Index = e.RowIndex Then
                         strID = Row.Cells(0).Value.ToString
                          Exit For
               End If
          Next

I have this same code setup in a Double Click event for the DataGridView. Also, the Row.Cell(0) depends on what column you have the RecordID. Good Luck.
 
Back
Top