Refresh Current Row of Datagridview

philiop

Member
Joined
May 6, 2010
Messages
22
Programming Experience
Beginner
Hi,

First of all, apologies for all of the posts at the moment.

I've got a DGV called DataGridView1 which is linked using a SQLTableadapter.

VB.NET:
        Dim ds As New DataSet
        DataGridView1.Columns.Clear()
        DataGridView1.DataBindings.Clear()
      
        connetionString = "Data Source=****;Initial Catalog=****;User ID=****;Password=****"
        connection = New SqlConnection(connetionString)
        sql = sSELECT & sFROM & sWHERE & sORDER

        Try
            connection.Open()
            adapter = New SqlDataAdapter(sql, connection)
            ds = New DataSet
            adapter.Fill(ds)
            connection.Close()
            Me.DataGridView1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

This code is handling the creation of the table and link perfectly. Now I want a better way of dealing with refreshing then just doing a refresh all.

We currently have 60,000 + clients held within one table of a SQL database and have around 30-40 people making constant changes to this table. What I want is a way to refresh the current selected clients information so that when anyone selects a client they are always seeing the most up to date information about them.

Is there anyway to do this? Or would just a large refresh like the above code be ok?
 
First up, your grid is not linked to the TableAdapter. They have nothing to do with each other. A TableAdapter is for populating a DataTable from a data source and saving changes back to that data source. A DataGridView is for displaying a list of data to the user and allowing them to edit that data. If I fill a glass of water and you drink it, that doesn't mean that we have any knowledge of each other at all.

As for the question, add another query to your TableAdapter that gets a single record by ID. You can then execute that query by calling the corresponding method of the TableAdapter. You can then call the Merge method of the original DataTable to merge the new table into it.
 
Back
Top