title: C# GetOleDbSchemaTable. Name of first Excel Worksheet and its columns
body: <pre><code>            try
              {
                  string connectionString = string.Empty;
  
                  if (Path.GetExtension(fileName) == ".xlsx")
                  {
                      connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName +
                          ";Extended Properties=Excel 12.0;";
                  }
                  else
                  {
                      Debug.Print(connectionString);
                      connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.Combine(Server.MapPath("~/Content"), fileName) + ";Extended Properties=Excel 8.0;";
                      //connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path.Combine(Server.MapPath("~/Content"), fileName) + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
                  }
  
                  OleDbCommand selectCommand = new OleDbCommand();
                  OleDbConnection connection = new OleDbConnection();
                  OleDbDataAdapter adapter = new OleDbDataAdapter();
                  connection.ConnectionString = connectionString;
  
                  if (connection.State != ConnectionState.Open)
                      connection.Open();
  
                  //connection.Get
                  DataTable dtSchema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  
  
              }
              catch (Exception ex)
              {
                  Debug.Print(ex.ToString());
              }
  </code></pre>
  
  <p>connection.Open() seems to be connecting just fine. Now I have gotten a dtSchema Data Table object. I am needing to get the name of the Excel worksheet or worksheets that were gotten if any. I am also scanning the object to find out where the column names are. There is supposed to be some columns in the schema. Is it documented where the columns are?
  When I do some output in my immediate window:</p>
  
  <pre><code>dtSchema.Columns[0].ToString()
  "TABLE_CATALOG"
  dtSchema.Columns[1].ToString()
  "TABLE_SCHEMA"
  dtSchema.Columns[2].ToString()
  "TABLE_NAME"
  dtSchema.Columns[3].ToString()
  "TABLE_TYPE"
  </code></pre>
  
  <p>These are not the column names of the first worksheet, which is what I am looking for mainly the name of the first worksheet and its columns.</p>
  
  <p>Thank you for posting..</p>