Mix Austria
Mix Austria

Reputation: 935

My Datagrid is repeating records

I have a button Load Table and a DataGrid. When I click the load table once it shows the records from my database. But when I click it again it just repeat it and the gridview shows repeating records. how can I make it refresh only and not adding the same records when i click the load table button?

Try
        con.Open()
        cmd = New SqlCommand("Select * from tblLogin", con)
        da.SelectCommand = cmd
        da.Fill(dt)
        bs.DataSource = dt
        DataGridView1.DataSource = bs
        da.Update(dt)

        con.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        con.Dispose()
    End Try

Upvotes: 0

Views: 40

Answers (1)

iCode
iCode

Reputation: 1346

Your DataTable object, dt, needs to have the Rows cleared before filling again. In C# it's dt.Rows.Clear()

Upvotes: 1

Related Questions