regd dataset
-
Hi, I have a dataset object and I am filling it with the rows of a table.Now I assigned it to a datagrid object.I don't know the schema of the table.Now I want the schema of the table and the data type of each attribute in the schema.How do I get this? Karteek
-
Hi, I have a dataset object and I am filling it with the rows of a table.Now I assigned it to a datagrid object.I don't know the schema of the table.Now I want the schema of the table and the data type of each attribute in the schema.How do I get this? Karteek
You can't get the schema from the
DataGrid
like you're probably hoping. You could construct anXmlDocument
(or use anXmlTextWriter
) to build a schema while enumerating through the tables and column definitions, but the easiest way is to create a typedDataSet
by adding a newDataSet
schema to your project and designing the desired schema in there. VS.NET can generate a typedDataSet
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 aDataGrid
. At the very least - if you don't want to use the actual typedDataSet
- you'll have a schema that you can use forDataSet.ReadXmlSchema
for a genericDataSet
instance. To bind to aDataGrid
, though, you really don't need to know the schema in advance. You can always set theDataGrid.DataSource
property to theDataSet
instance (filled) and optionally set theDataMember
tomyDataSet.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 theDataGrid.DataMember
property to the table name and add aDataGridTableStyle
toDataGrid.TableStyles
that uses the same table name. Optionally, you can add variousDataGridColumnStyle
sd to the associatedDataGridTableStyle.GridColumnStyles
collection property and setDataGrid.AutoGenerateColumns
tofalse
. See the documentation for any one of the mentioned classes and / or properties for more information and examples.Microsoft MVP, Visual C# My Articles