Hello, I have a webform with a datagrid and I receive the following error when doing the update command in the datagrid after editing it:
"Cannot update identity column 'Id_FHora_Horas'"
Here is the code for the datagrid update command:
Code:
Private Sub dgeditponto_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgeditponto.UpdateCommand
'colcoar o valor da ddl no campo da fk
CType(e.Item.Cells(5).Controls(0), TextBox).Text = _
CType(e.Item.FindControl("ddlE_S2"), DropDownList).SelectedItem.Value()
'encher o dataset
FHorasDataAdapter2.Fill(DataSetE_S1)
TipoMovDataAdapter3.Fill(DataSetE_S1)
'identificaar a linha a editar
Dim objEditRow As DataRow = DataSetE_S1.Tables(0).Rows.Find(CType(e.Item.Cells(5).Controls(0), TextBox).Text)
'andar através das celulas da datagrid e colocar a informação no dataset
Dim intCount As Integer
For intCount = 0 To e.Item.Cells.Count - 3
If e.Item.Cells(intCount).Controls.Count > 0 Then
If TypeOf (e.Item.Cells(intCount).Controls(0)) Is TextBox Then
'se é uma etxtbox com dados...
Dim strValue As String = CType(e.Item.Cells(intCount).Controls(0), TextBox).Text
'colocar o valor (or ou o nulo...) no campo respectivo do dataset
If strValue = "" Then
objEditRow.Item(dgeditponto.Columns(intCount).SortExpression) = System.DBNull.Value
Else
If intCount <> 2 Then
objEditRow.Item(dgeditponto.Columns(intCount).SortExpression) = strValue
End If
End If
End If
End If
Next
''uptade backend data
FHorasDataAdapter2.Update(DataSetE_S1, "fhoras_horas")
'deselecciona items da datagrid e faz o rebind
With dgeditponto
.SelectedIndex = -1
.EditItemIndex = -1
.DataSource = DataSetE_S1
.DataBind()
End With
End Sub
Any suggestions? :(
Thanks,
Elisa Resina