I followed an example but it seems to delete the record but when i go to access database the record was not deleted why ?
Here is my code:
Here is my code:
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
Dim strCaminho As String = Server.MapPath("~/adm/bd/observatorio.mdb") |
Dim MyOleDbConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strCaminho & ";") |
Dim MyOleDbDataAdapter As New OleDbDataAdapter |
MyOleDbDataAdapter.SelectCommand = New OleDbCommand("Select distinct news_id,news_titulo,news_dtinclusao from tblNoticias order by news_dtinclusao desc", MyOleDbConnection) |
Dim myDataTable As DataTable |
If Not (Session("DataSource") Is Nothing) Then |
myDataTable = CType(Session("DataSource"), DataTable) |
Else |
Try |
myDataTable = New DataTable |
MyOleDbConnection.Open() |
Try |
MyOleDbDataAdapter.Fill(myDataTable) |
Catch ex As Exception |
Me.lblError.Text = "Ocorreu um erro na tentativa de carregar os dados !" |
'Me.lblError.Text = ex.Message |
Exit Sub |
Finally |
MyOleDbConnection.Close() |
End Try |
Catch ex As Exception |
Me.lblError.Text = "Não foi possível abrir o banco de dados" |
'Me.lblError.Text = ex.Message |
Exit Sub |
End Try |
myDataTable.PrimaryKey = New DataColumn() {myDataTable.Columns("news_id")} |
Session("DataSource") = myDataTable |
End If |
RadGrid1.DataSource = myDataTable |
End Sub |
Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) |
Dim table As DataTable = CType(Session("DataSource"), DataTable) |
Dim ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("news_id").ToString() |
If Not (table.Rows.Find(ID) Is Nothing) Then |
table.Rows.Find(ID).Delete() |
table.AcceptChanges() |
Session("DataSource") = table |
End If |
End Sub |