title: Get the column names of a table and store them in a string or var c# asp.net
body: <p>I was wondering how I could get the columns of a database table and store each of them in a string or string array. I have the following code but I believe it does not work. I'm using the default table that is given in asp.net. I've been able to write to this table no problem but I cannot figure out how to select from it and save the values retrieved. here is what I have in my code behind</p>
  
  <pre><code>    string connection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
      SqlConnection conn = null;
      conn = new SqlConnection(connection);
      conn.Open();
      using (SqlCommand cmd = new SqlCommand())
      {
  
          string query = String.Format("SELECT column_name FROM USER_TAB_COLUMN WHERE table_name = 'TestTable'");
          cmd.Connection = conn;
          cmd.CommandType = CommandType.Text;
          cmd.CommandText = query;
          columns.Text = cmd.ExecuteNonQuery().ToString();
          conn.Close();
      }
  </code></pre>
  
  <p>the error is <code>Invalid object name 'USER_TAB_COLUMN'</code>. I've tried removing this and using <code>"SELECT column_name FROM TestTable"</code> then it complains about <code>column_name</code>. Columns is a text box by the way.</p>