Click here to Skip to main content
15,886,080 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm having trouble finding a solution for refreshing my datagridview. My goal is to have a refresh button that will automatically update the database(excel worksheet) after making a change and pressing the refresh button. The way my program responds: I make a change to the datagridview and press my refresh button, the program loads and then reverts back to the original data. Here is how my code looks so far.


VB
MyCommand1 = New OleDbDataAdapter("select * from [MyExcel$A13:x150]", MyConnection)

       DataSet1 = New System.Data.DataSet()
       MyCommand1.Fill(DataSet)


       'This displays the data to the GUI but does not save it to the DB table that we ultimately want it saved to
       DataGridView1.DataSource = DataSet1.Tables(0).DefaultView





VB
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Try
                oledbCmdBuilder = New OleDbCommandBuilder(oledbAdapter)
                changes = DataSet1.GetChanges()
                If changes IsNot Nothing Then
                oledbAdapter.Update(DataSet1.Tables(0))
            End If
            DataSet.AcceptChanges()
            MsgBox("Save changes")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class
Posted

1 solution

you may call the form constructor in refresh button
Form1_Load(sender, e);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900