title: From C#, how to find the names of the columns of a table in SQL Server?
body: <p>I can find and display all names of all tables in a listbox.</p>
  
  <p>But I need display column names of selected table from listbox by click a button.</p>
  
  <p>My function :</p>
  
  <pre><code>public void GetTableNames()
  {
      string strConnect = "Data Source=;Initial Catalog=DATA;User ID=sa;Password=***";
      using (SqlConnection con = new SqlConnection(strConnect))
      {
          con.Open();
  
          using (SqlCommand com = new SqlCommand(@"SELECT * FROM INFORMATION_SCHEMA.TABLES
                                                   WHERE TABLE_TYPE='BASE TABLE'  
                                                   ORDER BY TABLE_NAME ASC ", con))
          {
              using (SqlDataReader reader = com.ExecuteReader())
              {
                  listBox2.Items.Clear();
                  int counter = 0;
                  while (reader.Read())
                  {
                      counter++;
                      listBox2.Items.Add((string)reader["TABLE_NAME"]);
                  }
  
                  lblTablesCount.Text = counter.ToString();
              }
          }
      }
  }
  </code></pre>
  
  <p>Call function in button</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)     
  {
      GetTableNames();
  }
  </code></pre>
  
  <p>My question : <strong>Given a selected table, how can I find the names of the columns of that table?</strong> The user picks the table from a listbox and clicks a button.</p>