0

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#

2
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by manugm_1987
0

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();
}
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.