0

I want to select column names of Table1 as rows of column1 of Table2 and data types of Table1 columns as rows of column2 of Table2.

So if Table1 is like this.

Name    Age Graduation Date
John    21  11.11.2015
Hillary 23  7.09.2015

I want to get this table by query.

Name    String
Age Long
Graduation Date Date

What should be my SQL query?

(I'm gonna use this in an Windows form application which uses OLEDB connection to get data from an mdb file.)

Jens
  • 67,715
  • 15
  • 98
  • 113
  • It seems that you are looking for [a previous post](http://stackoverflow.com/questions/1054984/how-can-i-get-column-names-from-a-table-in-sql-server) like this one. – ThanosK Mar 30 '17 at 13:28

1 Answers1

0

I'm gonna use this in an Windows form application which uses OLEDB connection to get data from an mdb file

You can get the informations you need via con.GetOleDbSchemaTable:

using (OleDbConnection connection = new OleDbConnection(connectionString))
{
    connection.Open();

    DataTable tableColumns = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, "Table1", null }));
    foreach (DataRow row in tableColumns.Rows)
    {
        var columnNameColumn = row["COLUMN_NAME"];
        var dateTypeColumn = row["DATA_TYPE"];
        var ordinalPositionColumn = row["ORDINAL_POSITION"];
        ...
    }
}

You will find column-names and types in this DataTable. Ref.

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939