title: Retrieve column names and types from SQL Server to DataTable C#
body: <p>What would be the best way of building an empty DataTable based on existing table in SQL server? My current try is this one, which is just retyping this manually, so it is not great, especially for large data sets.</p>
  
  <pre><code>private DataTable createEmptyReadingDataTableReadyToSaveToDb()
  {
      dtbl.Columns.Add("ProductId", typeof(string));
      dtbl.Columns.Add("Price", typeof(float));
      dtbl.Columns.Add("Revenue", typeof(float));
      dtbl.Columns.Add("URL", typeof(string));
      //  etc ....
      return dtbl;
  }
  </code></pre>
  
  <p>I read today about schemas, which seem natural for this task. It got me more confused than I thought this would be. Anyways such approach below returns a datatable returning broad set of information about the dataset, but I do not find there accessors to get information about the interesting DataTable (below). Probably I do something wrong.</p>
  
  <pre><code>private static DataTable getReadingTableFromSchema()
  {
      using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalDbConnnectionString"].ConnectionString))
      {
          string sql = "SELECT * FROM [Readings]";
          conn.Open();
          SqlCommand cmd = new SqlCommand(sql, conn);
          SqlDataReader reader = cmd.ExecuteReader();
          DataTable dtbl = reader.GetSchemaTable();
          return dtbl;
      }
  }
  </code></pre>
  
  <p>I could also just try the approach with DataAdapter reading the data, then filling it (basically copying the DataTable) and then deleting all rows to have the table empty - but this would definitely affect the performance. What would be the right solution?</p>