using readxmlschema to create dataset as datasource for datagridview

I tried to create a dataset from an xml document and then set the datasource for the datagridview to that dataset. The program ran but the datagridview doesn't show any data. Here is the relevant code :

Dataset ds = new DataSet();

ds.ReadXmlSchema(fileName);

dataGridView.DataSource = ds;



Answer this question

using readxmlschema to create dataset as datasource for datagridview

  • James Avery

    ReadXmlSchema doesn't load any data, it just sets up the tables, columns, constraints and so on. Try using ReadXml after you read the schema.


  • Kevin Zhang

    Thank you for your response. I tried using ReadXml method, but I received no results in the datagridview. I have a feeling that the answer lies in the fact that I have not named the DataMember property ( for the reason that I don't know how to name it - the title of the xml document is <emperors> but that didn't work as a DataMember - it caused an exception ) . Is there a way to identify a datamember from an xml document This is the first line in the document : <emperors> , but this does not work as a datamember.


  • Miguel Angel Nieto

    I was subsequently able to obtain the TableName of the xml document by

    ds.Tables[0].TableName

    and then that name was assigned as DataMember.So, it seems that a datamember must always be assigned.


  • using readxmlschema to create dataset as datasource for datagridview