Hello everyone

How can i get all the table names of database and display these table names using combo box. Or store the table names in an array . I am using sqlexpress and c#

Write this query:

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

For further info go here.

To get table name into comboBox, you can use dataReader class, and while looping through the database, add their names into comboBox:

string connectionString = @"yourConnStringHere";
using (SqlConnection sqlConn = new SqlConnection(connectionString))
{
    SqlCommand cmd = connection.CreateCommand();
    cmd.CommandText = "SELECT table_name AS Name FROM
              INFORMATION_SCHEMA.Tables WHERE TABLE_TYPE = 'BASE TABLE'";
    connection.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    while(readr.Read())
         comboBox1.Items.Add((string)reader[0]);
    reader.Dispose();
    cmd.Dispose();
}

Write this query:

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

For further info go here.

To get table name into comboBox, you can use dataReader class, and while looping through the database, add their names into comboBox:

string connectionString = @"yourConnStringHere";
using (SqlConnection sqlConn = new SqlConnection(connectionString))
{
    SqlCommand cmd = connection.CreateCommand();
    cmd.CommandText = "SELECT table_name AS Name FROM
              INFORMATION_SCHEMA.Tables WHERE TABLE_TYPE = 'BASE TABLE'";
    connection.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    while(readr.Read())
         comboBox1.Items.Add((string)reader[0]);
    reader.Dispose();
    cmd.Dispose();
}

Thanks a lot for your precious help :)

Your are welcome. I hope you make it :)

Your are welcome. I hope you make it :)

Ya its working fine :) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.