G
Guest
Hi all
I am having a problem saving the contents of an edited datagrid back to the underlying SQL CE Database. I'm fairly new to .Net so I'm not even sure if this is possible.
I have a datagrid on my form which I have populated using a datatable
fstrTableName = strTableName
strSQL = "Select * From " & fstrTableName
Dim cmd As New SqlCeCommand(strSQL, ssceconn)
da = New SqlCeDataAdapter(cmd)
fsqlCB = New SqlCeCommandBuilder(da)
da.UpdateCommand = fsqlCB.GetUpdateCommand
table.TableName = fstrTableName
da.Fill(table)
DataGrid1.DataSource = table
This bit seems to work fine.
I then have a text box on my form which gets populated with the contents of each cell on the grid as you navigate around (copied from an example somewhere). If the user then updates the value in the text box, it is then updated automatically in the grid.
currentCell = DataGrid1.CurrentCell
table.Rows(currentCell.RowNumber).BeginEdit()
table.Rows(currentCell.RowNumber).Item(currentCell.ColumnNumber) = currentCellData
table.Rows(currentCell.RowNumber).EndEdit()
table.AcceptChanges()
Me.DataGrid1.Update()
This also seems to work fine.
However, when I close the form the changes are not being saved to the underlying database. I am doing a da.Update(table) in the closing form procedure, but this does not seem to make any difference.
Does anyone know whether what I am doing is possible, and if so, where I am going wrong.
Thanks
I am having a problem saving the contents of an edited datagrid back to the underlying SQL CE Database. I'm fairly new to .Net so I'm not even sure if this is possible.
I have a datagrid on my form which I have populated using a datatable
fstrTableName = strTableName
strSQL = "Select * From " & fstrTableName
Dim cmd As New SqlCeCommand(strSQL, ssceconn)
da = New SqlCeDataAdapter(cmd)
fsqlCB = New SqlCeCommandBuilder(da)
da.UpdateCommand = fsqlCB.GetUpdateCommand
table.TableName = fstrTableName
da.Fill(table)
DataGrid1.DataSource = table
This bit seems to work fine.
I then have a text box on my form which gets populated with the contents of each cell on the grid as you navigate around (copied from an example somewhere). If the user then updates the value in the text box, it is then updated automatically in the grid.
currentCell = DataGrid1.CurrentCell
table.Rows(currentCell.RowNumber).BeginEdit()
table.Rows(currentCell.RowNumber).Item(currentCell.ColumnNumber) = currentCellData
table.Rows(currentCell.RowNumber).EndEdit()
table.AcceptChanges()
Me.DataGrid1.Update()
This also seems to work fine.
However, when I close the form the changes are not being saved to the underlying database. I am doing a da.Update(table) in the closing form procedure, but this does not seem to make any difference.
Does anyone know whether what I am doing is possible, and if so, where I am going wrong.
Thanks