How can one retrieve the tables’ names into a List<string> from a specific database on a server?
How can one retrieve the tables’ names into a List<string> from a specific database
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
System.Data.SqlClienthas what you need without a formal query on sys.Tables (though that’s what it’s using in the background). Use theGetSchema()method on theSqlConnectionobject and designate that you want the “Tables” and it will send you aDataTableobject back with a row for each table. It sends back database name, table schema name, table name, and table type in each row (in that column order). The code would look like this: