I have a grid (Infragistics.Win.UltraWinGrid.UltraGrid v11.1) editable and updateable, where I set it manually and run-time allocation of the Grid's DataSource to a DataSet manually defined,Me.Grid.DataSource = pDataSet.Tables ("ARTICLES"): Private Sub FillArticles() Dim cm As IDbCommand Dim dp As IDataParameter 'create command cm = cn.CreateCommand 'create Adapter pAdArticulos = MDatos.DataAdapterCrear(cm) 'create dataset pDataSet = New DataSet 'create datatable pDtArticulos = New DataTable("ARTICLES") 'add datatable to dataset pDtArticulos = pDataSet.Tables.Add("ARTICLES") 'create el parameter dp = MDatos.ConexionParameter(cm, "ART_EMPRESA", pIdEmpresa) 'dml cm.CommandText = " SELECT ART_EMPRESA, ART_ARTICULO, V_ASP_ART_DESCRIPCION, ART_FAMILIA, ART_FAMILIA_ALTERNATIVA" cm.CommandText &= " FROM " & MDatos.BDOwner(cn, "EMRES_ARTICLES", "main") cm.CommandText &= " WHERE ART_EMPRESA = " & dp.ParameterName cm.CommandText &= " ORDER BY ART_ARTICULO" 'fill dataset with table ARTICLES pAdArticulos.Fill(pDataSet, "ARTICLES") 'define primary key pDtArticulos.PrimaryKey = New DataColumn() {pDtArticulos.Columns("ART_EMPRESA"), pDtArticulos.Columns("ART_ARTICULO")} 'assigned DataSet to DataSource Me.Grid.DataSource = pDataSet.Tables("ARTICLES") Me.Grid.DisplayLayout.Bands(0).Columns("ART_EMPRESA").Hidden = True Me.Grid.DisplayLayout.Bands(0).Columns("ART_ARTICULO").Width = 120 Me.Grid.DisplayLayout.Bands(0).Columns("ART_FAMILIA").Width = 220 Me.Grid.DisplayLayout.Bands(0).Columns("ART_FAMILIA_ALTERNATIVA").Width = 220 End Sub When making any change, delete or insert a new row in the grid, the grid detects changes, and in the event AfterRowUpdate, I execute the UpdateData, but changes are not saved in the database. Private Sub Grid_AfterRowUpdate(sender As Object, e As Infragistics.Win.UltraWinGrid.RowEventArgs) Handles Grid.AfterRowUpdate 'exit cell editing to save your changes Me.Grid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ExitEditMode) Try Me.Grid.UpdateData() Catch ex As Exception Throw ex End Try End Sub How can I define it to save the changes automatically when you run Me.GridUdateData??? Thank for advance(Any code example to set the grid's DataSource manually, please??), but changes are not saved in the database.
Hi,
There is no reason to call the UpdateData method inside AfterRowUpdate. That line of code will do nothing.
UpdateData commits all changes in the grid to the underlying data source. AfterRowUpdate fires after the row's data has already been committed. So this is just redundant.
ddol said:but changes are not saved in the database.
The grid has no direct interaction with the database - it only deals with the local data source. So writing changes from the DataSet back to the database is outside the grid's purview.
Typically, you would use a DataAdapter to retrieve and update data to and from a DataSet. For more information on the DataAdapter, you will need to check out Microsoft's documentation.
The DataSet and DataAdapter pAdArticulos is associated with: pAdArticulos.Fill (pDataSet, "ARTICLES")with what changes should be saved in the database.At what point I will have to execute 'Me.Grid.UpdateData()' to save changes?The way in which I am using the grid and I associating DataSource is correct?Some code samples?
You typically never need to call UpdateData. The grid automatically saves the changes to it's DataSource any time you move to another cell or the grid loses focus. You can change this via the UpdateMode property.
The only time you need to use UpdateData is if you need to force the update to occur without changing cells or losing focus on the grid. For example, if you click on a Toolbar button. Toolbars don't take focus, so therefore the grid will not lose focus when you click one. So in that case, you could use UpdateData to ensure that all changes are committed.
ddol said:The way in which I am using the grid and I associating DataSource is correct?
It's hard to say without running the code, but it looks okay to me. If your data is displaying in the grid, then it's clearly working.
ddol said:Some code samples?
As I said, updating the back end is unrelated to the grid. I'm sure Microsoft has code sample of using the DataAdapter class to update the database using it's Update method.
OK, besides to save change in the grid, will use the DataAdapter for save changes in database.Thank you for all.