How I can save a DatagridView in a Xml and Load A Xml to datagridView?

前端 未结 1 1956
天涯浪人
天涯浪人 2021-01-22 02:45

Hi I want to save and load data from a datagridview to a xml. My idea is that I can save my datagridview to a xml how this -> \"[date]_[name].xml\" and later I can load this dat

相关标签:
1条回答
  • 2021-01-22 03:23

    This is the sample xml file which I have used for testing your scenario:

    <dataset>
      <student>
        <name>Tarasov</name>
      </student>
    </dataset>
    

    The sample code snippet which could access the above mentioned XML file:

    private void Load()
    {
        string path = @"C:\dataset.xml";
        DataSet ds = new DataSet();
        ds.ReadXml(path);
        InputDataGrid.DataSource = ds;
        InputDataGrid.DataMember = "student";
    }
    
    private void Save()
    {
        string path = @"C:\dataset.xml";
        DataSet ds = (DataSet) InputDataGrid.DataSource;
        ds.WriteXml(path);
    }
    

    --SJ

    0 讨论(0)
提交回复
热议问题