overwriting datatable with new values

reddzer

Member
Joined
Apr 20, 2007
Messages
6
Programming Experience
Beginner
i have the following piece of code. i fill a datatable with values and add it to a dataset and display then in a datagridview. i then have a msgbox, after this i fill the datatable with different values and display the new values in the datagridview.

the problem is it now displays the values from both tables.

how can i overwrite the datatable so that it only contains the values of the second table

VB.NET:
        Dim ds As DataSet = New DataSet()
        Dim dt As DataTable = New DataTable()
                
        Dim queryAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM table1", conn)
        ds.Tables.Add(dt)
        queryAdapter.Fill(dt)
        grid1.DataSource = ds.Tables(0).DefaultView
 
        MsgBox("")
        
        Dim queryAdapter2 As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("SELECT * FROM table2", conn)
        queryAdapter2.Fill(dt)
        grid1.DataSource = ds.Tables(0).DefaultView
 
VB.NET:
dt.Clear()
dt.Columns.Clear()
or
VB.NET:
dt.Rows.Clear()
dt.Columns.Clear()
Works.

Has the same effect as reset but the values appear without having to click a column on the datagridview
 
Back
Top