Export datagridview to Xml

inkedGFX

Well-known member
Joined
Feb 2, 2013
Messages
142
Programming Experience
Beginner
I am attempting to save the contents of a datagridview to an Xml file...I get an error saying "object refrence not set to an instance of an object"

I fill the datagridview before trying to save the data...here is the save code

  private void WriteXml(string path)        {
            try
            {
                //BindingSource bs = (BindingSource)dataGridView1.DataSource;
                DataSet ds = new DataSet();
                ds = (DataSet)(dataGridView1.DataSource);
                
                ds.WriteXml(path, XmlWriteMode.IgnoreSchema);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR\r\n" + ex.Message);
            }
        }


any help would be appreciated

Thank You
InkedGFX
 
Back
Top Bottom