views:

563

answers:

2

how do i dynamically bind different tables from DB with different columns into gridview?

Actually, i was using OleDbDataAdapter to to join the SQL statement and put in a DataTable but my question is, let says, i execute 1st SQL statement and when i execute 2nd SQL statement, the data adapter will use back the 1st SQL statement. So, i was thinking how to make the data adapter to clear off the 1st SQL statement before executing the 2nd statement???

+2  A: 

Here are three possible solutions from easiest to hardest:

  1. Join the tables in a view and select against the view for your data source.
  2. Join the tables in a SQL statement and use that as your data source.
  3. Create a new bindable collection (probably a DataTable) and dynamically add data from the two tables to it. Use that as your data source.
Jamie Ide
A: 

You always have dtbl1.Merge(dtbl2);

JBrooks