-2

I have a dataGridView and so far I can make it show one table at a time.

Let's say I want to add a button which will jump to the next table in my database.

for example, if my database contains the tables A, B and C. I will assign my datagridview to show table A by default.

How do I make it show table B just by using a button?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
icarus
  • 166
  • 1
  • 6
  • 14
  • Use an [Event Handler](http://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp)...? – Brian Jun 05 '13 at 16:13

1 Answers1

1

You can make a query which returns names of all tables in database like

USE your_database
SELECT name FROM sys.tables

Save the names of tables in a list and on button click pass name of next table to a query to show its data in gridview.

mck
  • 978
  • 3
  • 14
  • 38
  • thank you. I was trying to use the built-in data adapters that c# automatically generates. I manually wrote everything, including that query. it works now. thank you. – icarus Jun 05 '13 at 16:58