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 :)

This article has been dead for over six months. Start a new discussion instead.