You can't get the schema from the DataGrid like you're probably hoping. You could construct an XmlDocument (or use an XmlTextWriter) to build a schema while enumerating through the tables and column definitions, but the easiest way is to create a typed DataSet by adding a new DataSet schema to your project and designing the desired schema in there. VS.NET can generate a typed DataSet class (with actual table and column names, as well as the proper column types and fewer look-ups). You can use this to bind more easily to a DataGrid. At the very least - if you don't want to use the actual typed DataSet - you'll have a schema that you can use for DataSet.ReadXmlSchema for a generic DataSet instance. To bind to a DataGrid, though, you really don't need to know the schema in advance. You can always set the DataGrid.DataSource property to the DataSet instance (filled) and optionally set the DataMember to myDataSet.Tables[0].TableName. By default, columns are generated automatically. If you know the schema up-front - you don't even have to import any schema - you can pre-set the DataGrid.DataMember property to the table name and add a DataGridTableStyle to DataGrid.TableStyles that uses the same table name. Optionally, you can add various DataGridColumnStylesd to the associated DataGridTableStyle.GridColumnStyles collection property and set DataGrid.AutoGenerateColumns to false. See the documentation for any one of the mentioned classes and / or properties for more information and examples.
Microsoft MVP, Visual C# My Articles