title: Retrieve DataTable info for a table in SQL Server
body: <p>I need to get the column names, primary keys, foreign keys, and other schema info. The <code>DataTable</code> class seem to contain all of those.</p>
  
  <p>Below is the current code I got so far. With it I could retrieve all info except the <em>foreign keys</em>. I'm expecting them to be defined in <code>DataTable.Constraints</code> but they are not. This is my current code:</p>
  
  <pre><code>    private static DataTable LoadSchemaInfo(string tableName, SqlConnection connection)
      {
          string cmdText = "SELECT * FROM [" + tableName + "] WHERE 1 = 0";
  
          // Create a SqlDataAdapter to get the results as DataTable
          var sqlDataAdapter = new SqlDataAdapter(cmdText, connection);
  
          // Create a new DataTable
          var dataTable = new DataTable(tableName);
  
          // Fill the DataTable with the result of the SQL statement
          sqlDataAdapter.FillSchema(dataTable, SchemaType.Source);
  
          return dataTable;
      }
  </code></pre>
  
  <p>Any idea how to retrieve all info or how to get the FK (preferably without using the pure SQL syntax because I would then lack of some compile-time checking)?</p>