Click here to Skip to main content
15,891,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a program to add/edit table enteries in a db in c#

I want to know whether we will be able to retrieve table names given a database name,say northwind.

please help me in this regard,as i am stuck with it.

Thanks in advance.
Posted

The following will work on most RDBM servers :
SQL
select *
from INFORMATION_SCHEMA.TABLES


The actual columns returned might vary between server types but the core ones TABLE_NAME etc. exist in all.
 
Share this answer
 
Try:
C#
using (SqlConnection con = new SqlConnection(strCon))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.sysobjects WHERE xtype = 'U'", con))
        {
        using (SqlDataReader r = cmd.ExecuteReader())
            {
            while (r.Read())
                {
                Console.WriteLine(r["name"]);
                }
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900