How to refresh a DataGridView after database Update.
Posted on 2007-04-09
How do you refresh a DataGridView with the current contents of the database after you do an UPDATE?
Private Sub btnUpdatePosition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdatePosition.Click
Dim rowsAffected As Integer = 0
rowsAffected = Me.ApplicantsTableAdapter.Update(Me.SYEP2007DataSet.Applicants)
MessageBox.Show(rowsAffected.ToString + " Rows were affected")
Dim con As New SqlConnection
Dim cmd As SqlCommand = New SqlCommand("dbo.spUpdate_JobTitles_PositionsAvailable", con)
con.ConnectionString = "workingConnectionString"
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
This button Updates the database, but the changes are not reflected in the DataGridView, JobTitlesDataGridView, until I exit the application and run it again.
I've searched the web for nearly a week now and none of the solutions work. Most give me an error right from the beginning. I'm using VS2005, VB.NET, SQL Server 2000.
The DataSource for the DataGridView is JobTitlesBindingSource