|
-
February 15th, 2011, 01:50 PM
#1
DataAdapter does not update a record
Hi, I have been researching all that is related to DataSources, DataReaders, DataAdapters, etc, with an Access 2010 DB bound to a DataGridView.
Everything is fine, just one line fails and is driving me nuts!
Here is the code:
Code:
Private Sub ModificaPrecios()
Dim mensaje As String
Dim variacion As Integer
Dim i As Int32
mensaje = "¿Esta seguro que desea "
If rdbAumento.Checked Then
mensaje = mensaje & "aumentar un "
Else
mensaje = mensaje & "descontar un "
End If
If txPorcentaje.Text.Length > 0 Then
mensaje = mensaje & txPorcentaje.Text & " porciento de sus listas de precios?"
If MessageBox.Show(mensaje, "Actualizo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
'I asked if user is sure to change the column
'rdbAumento states whether the column value is increased or decreased
If rdbAumento.Checked Then
variacion = Convert.ToInt32(txPorcentaje.Text)
For i = 0 To gridPrecios.Rows.Count - 2
gridPrecios.Item(5, i).Value = (gridPrecios.Item(5, i).Value * (100 + variacion) / 100)
Next
Else
variacion = Convert.ToInt32(txPorcentaje.Text)
For i = 0 To gridPrecios.Rows.Count - 2
gridPrecios.Item(5, i).Value = (gridPrecios.Item(5, i).Value * (100 - variacion) / 100)
Next
End If
End If
End If
UpdateGrilla()
End Sub
Private Sub UpdateGrilla()
Dim cb As New OleDb.OleDbCommandBuilder(da)
'If txporcentaje.text is not null, then user increased or decreased ALL THE COLUMN with the For above. Else, The user just changed ONCE CELL MANUALLY
If txPorcentaje.Text <> nothing Then
If MsgBox("Desea guardar los cambios realizados?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "WARNING") = MsgBoxResult.Yes Then
'This line is failling. See below for description
da.Update(ds, "datos")
'Hubocambio se usa para meter datos a HistorialPrecios
hubocambio = True
End If
Else
If MsgBox("Save data?.", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "WARNING") = MsgBoxResult.Yes Then
'The odd thing that is killing me is that this line is NOT failing.
da.Update(ds, "datos")
'Hubocambio se usa para meter datos a HistorialPrecios
hubocambio = True
End If
End If
If hubocambio Then
InsertaCambioPrecio()
End If
End Sub
Private Sub InsertaCambioPrecio()
'Some routine that saves a record as a log of what is being done.
End Sub
The line that fails, actually updates my database, but somehow, the update is not performed on the line that belongs to the first row of the grid. What is more, if I change the value manually, the same update method works fine. What is going on here?
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|