Yes, I see what happend. My mistake. My comment about the primary key was
mainly intended as a reminder that you cannot search the table using the
rows.find method unless you have a primary key. You got a concurrency
exception because you changed the table definition (by adding a primary key)
then attempted to update the table on the database (which the DataAdapter
would not do).
Since your table defintion does not have a primary key on it, you can select
the row using a filter on the dataview like this:
Dim MyDataKey As String = DataGrid1.DataKeys(e.Item.ItemIndex)
Dim tbl As DataTable
'this will filter the datatable based on the column designated as chosen
datakey
Dim dvFound As New DataView(tbl, "FieldNameOfPrimaryKey='" & MyDataKey &
"'", Nothing, DataViewRowState.CurrentRows)
If dvFound.Count = 1 Then 'if there is a record that match this Datakey
dvFound(0).Delete()
adp.Update(DsLITAdminNovosti)
DataGrid1.DataBind()
End If
--
HTH,
Phillip Williams
http://www.societopia.net http://www.webswapp.com
"papaja" wrote:
Here is entire subroutine as it is in my page.
It does not delete rows, and sometimes it reports the following error:
Concurrency violation: the DeleteCommand affected 0 records.
*******************************
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.DeleteCommand
Dim primaryKey As String = DataGrid1.DataKeys(e.Item.ItemIndex)
'Notice you cannot use the Find method on the rows collection
unless you have
'a primary key set on your DataTable, e.g,
Dim keys(0) As DataColumn
keys(0) = DsLITAdminNovosti.tblLITNovosti.Columns(0) 'select
the first column as the primary key
DsLITAdminNovosti.tblLITNovosti.PrimaryKey = keys
Dim foundRow As DataRow =
DsLITAdminNovosti.tblLITNovosti.Rows.Find(primaryK ey)
If Not foundRow Is Nothing Then 'if the row is not deleted
yet
foundRow.Delete()
adp.Update(DsLITAdminNovosti)
DataGrid1.DataBind()
End If
End Sub
*******************************
Did I misunderstood something?