Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to loop through tables in the database

Status
Not open for further replies.

jgd123456

Programmer
Nov 3, 2006
19
GB
Hi how do you loop through all the tables in a database and then for all the rows within the table (sub loop)

So far i've got (not sure how much is right):

SqlConnection db = new SqlConnection(_connectionString);
string[] restrictions = new string[2] {"DatabaseName", null};
db.Open();
DataTable tables = db.GetSchema("Tables", restrictions);
db.Close();

for (int i = 0; i <= tables.Rows.Count; i++) {
Response.Write(tables.Rows["table"]);
}

I understand this is the way to go in asp.net 2.0 but i can't see how to get the tablename from the row in the datatable collection. I then need to do a sub loop to loop through the columns within that table.

Really appreciate it if someone could help.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top