Murray Brown
asked on
VB.net DataGridView not clearing
Hi
I am using the following VB.net code to bind data to a DataGridView.
When I add additional data to my table I call this procedure again but it
doesn't clear the data but rather just adds to the list. How do I get the data in the grid to
clear then populate so it shows what is actually in the table.
Thanks
I am using the following VB.net code to bind data to a DataGridView.
When I add additional data to my table I call this procedure again but it
doesn't clear the data but rather just adds to the list. How do I get the data in the grid to
clear then populate so it shows what is actually in the table.
Thanks
Sub Fill_DGV() '*
Dim dbadp As OleDbDataAdapter '*
Dim dTable As New DataTable '*
Try '*
Me.DataGridView1.DataSource = Nothing
Dim sSQL As String '*
sSQL = "SELECT * FROM [Bookings]" '*
Dim connection As New OleDbConnection(ConnectionString) '*
dbadp = New OleDbDataAdapter(sSQL, connection) '*
dbadp.Fill(dTable) '*
Me.DataGridView1.DataSource = dTable '*
Catch ex As Exception '*
MsgBox(ex.Message) '*
End Try '*
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
None of this worked. I even tried the following to no avail:
Me.DataGridView1.DataSourc e = Nothing
Me.DataGridView1.Rows.Clea r()
None of this worked. I even tried the following to no avail:
Me.DataGridView1.DataSourc
Me.DataGridView1.Rows.Clea
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi
dTable.Clear()
did the trick. there were duplicate rows, but all works well now
dTable.Clear()
did the trick. there were duplicate rows, but all works well now
You probably did not have
>Dim dTable As New DataTable
because that would have done the trick anyway.
>Dim dTable As New DataTable
because that would have done the trick anyway.
ASKER
Thank you very much
Open in new window