borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (help me in this plz..)Next Topic (Help) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Refresh DataSet after undeleteing a row
Poster Message
Afshin_Zavar
Level: Professor


Registered: 17-07-2003
Posts: 84

Ads by Lake Quincy Media
icon Refresh DataSet after undeleteing a row

These are my pieces of code

Undo the changes (edit, delete and new row) :
        If myDataset.HasChanges Then myDataset.RejectChanges()


Deletion method:

        Dim currentID As Integer = 0    
        currentID = Me.BindingContext(myDataset, "Employees").Position
        myDataset.Tables(0).Rows.RemoveAt(currentID)


But after the changes, which have made to DataSet , I have to refresh DataSet, to show all rows.

        myDataset.Clear()
myDataAdapter.Fill(myDataset, "Employees")


Any idea?!

[Edited by Afshin_Zavar on 23-02-2009 at 07:50 AM GMT]

____________________________
Persia

16-02-2009 at 01:08 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1060
icon Re: Refresh DataSet after undeleteing a row

Hi
I've never seen this behaviour - have you inspected the actual rows that should've undone the changes or are you just seeing the displayed values? For example, a bound datagrid may not reflect the changes until you rebind it.
Also, is this asp or vb.net?

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

Ads by Lake Quincy Media
23-02-2009 at 12:15 AM
View Profile Send Email to User Show All Posts | Quote Reply
Afshin_Zavar
Level: Professor


Registered: 17-07-2003
Posts: 84
icon Re: Refresh DataSet after undeleteing a row

Sorry i didn't understand, what you meant ! but the big problem is that i always have to reFill adapter to see the changes.
I think in big queries, it may have overload to DB. So i try to find a solution
by the way, it is VB.NET

   Private Sub btnReload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles btnReload.Click

        Select Case myConnection.State
            Case ConnectionState.Closed
                myConnection.Open() ' try to open
            Case ConnectionState.Open
                myDataset.Clear()   ' allready opened? then reresh
        End Select

        myDataAdapter.Fill(myDataset, "Employees")

        With DataGridView1
            .DataSource = myDataset
            .DataMember = "Employees"
        End With

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles btnCancel.Click
        myDataset.RejectChanges()
       btnReload_Click(sender, e)
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles btnDelete.Click
        Dim currentID As Integer = 0
        currentID = Me.BindingContext(myDataset, "Employees").Position
        myDataset.Tables(0).Rows.RemoveAt(currentID) 'mark as deleted
    End Sub

   Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles btnSave.Click

        Dim TempDataSet As DataSet = New DataSet()

        If myDataset.HasChanges Then

            Me.BindingContext(myDataset, "employees").EndCurrentEdit()

            TempDataSet = myDataset.GetChanges 'read all changes

            For Each dr As DataRow In TempDataSet.Tables(0).Rows
                If Not dr.RowState = DataRowState.Deleted Then 'deleted row has nothing to check, so skip it
                    If dr("Title").ToString() = String.Empty Then
                        MsgBox("Title is empty")
                        dr.RejectChanges()  ' reject only unwanted row!
                    End If
                End If
            Next
            myDataAdapter.Update(TempDataSet.Tables(0))
            myDataset.AcceptChanges() 'Commit changes to a dataset
            btnReload_Click(sender, e)
        End If
    End Sub


____________________________
Persia

23-02-2009 at 07:48 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1060
icon Re: Refresh DataSet after undeleteing a row

After you call AcceptChanges.. does MyDataset have the correct data in without refilling (look at the dataset, not at any display databindings)

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

23-02-2009 at 10:54 PM
View Profile Send Email to User Show All Posts | Quote Reply
Afshin_Zavar
Level: Professor


Registered: 17-07-2003
Posts: 84
icon Re: Refresh DataSet after undeleteing a row

I think it doesn't , so i have to re-Execute query to fetch new rows

____________________________
Persia

24-02-2009 at 06:12 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1060
icon Re: Refresh DataSet after undeleteing a row

Hi
Ive attached a sample project calling rejectchanges that does not need refilling from the db.
Can you have a look and compare it to your scenario?
As indicated, I resetallbindings and the controls refresh from the d/s without needing to refill from the d/b

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

____________________________
Attached:
Andreavb_Rejct.zip 184 KB (Downloads: 17)

24-02-2009 at 06:51 PM
View Profile Send Email to User Show All Posts | Quote Reply
Afshin_Zavar
Level: Professor


Registered: 17-07-2003
Posts: 84
icon Re: Refresh DataSet after undeleteing a row

It was frankly useful... thank you.

____________________________
Persia

24-02-2009 at 07:41 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : VB.Net : Refresh DataSet after undeleteing a row
Previous Topic (help me in this plz..)Next Topic (Help) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder