
February 13th, 2003, 05:42 PM
|
|
Registered User
|
|
Join Date: Feb 2003
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Updating DataSet from an edited DataGrid
I have a DataGrid that allows editing of records. I have taken over the OnUpdateCommand event and I wish to move the edited values back into the proper DataRow of a persisted dataset. Basically, I want to let the user modify one or more rows and then update them all in a single batch operating using the DataAdapter.Update( dataset ) command.<br><br>All the examples that I have seen to update a DataSet from the DataGrid use code like below. Basically, it has hardwired code grabbing the values from the grid Cell Controls into known hardwired variables. I was hoping to make something a little more generic so it could handle almost any DataGrid and any DataSet using the bounded column caption and the DataSet column caption. For example, I would think that I should be able to loop through the columns of the datagrid, find the Bounded Column object, get its DataField value, get the edited text value, find the associated column/row in the dataset and update it. But, can't find a way of doing this, any suggestions...<br><br>Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )<br> Dim conn As SqlConnection<br> Dim MyCommand As SqlCommand<br> Dim strConn as string = "server=YourServer;uid=UID;pwd=PWD;database=Northwi nd"<br><br> ' Hardwired knowledge of the datagrid columns (not generic!)<br> Dim txtFirstName As textbox = E.Item.cells(2).Controls(0)<br> Dim txtLastName As textbox = E.Item.cells(3).Controls(0)<br> Dim txtTitle As textbox = E.Item.cells(4).Controls(0)<br><br> ' Code here to either update the DataSet directly or call SQL update command<br> ' code removed for this example....<br><br> MyDataGrid.EditItemIndex = -1<br> BindData<br>End Sub<br><br>Thanks for any help,<br>Ron
|