This is a migrated thread and some comments may be shown as answers.

Still trying to delete record of my grid...

1 Answer 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edmond Junior
Top achievements
Rank 1
Edmond Junior asked on 07 Mar 2009, 12:56 AM
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:

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 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 10 Mar 2009, 11:41 AM
Hello Edmond,

In the example shown, you are simply modifying the cached version of the datasource. You need to prepare and execute an update command directly against the underlying datasouce, be it Access/SqlDatasource, to ensure that the data is persisted as expected.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Edmond Junior
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or