Click here to Skip to main content
15,796,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys Its throwing this error when i try to save the contents of my SQL database table to an XML file, any idea where i am going wrong, it would be much appreciated if you could help. thanks Louise :) x

private void databasexml_Click(object sender, EventArgs e)
            string sql = "SELECT * FROM BookDetails";
            DataSet ds = new DataSet();
            BindingSource bs = new BindingSource();
            SqlDataAdapter sda = new SqlDataAdapter(sql, stringConnection);

            ds.WriteXml("C:\\Users\\Louise Tooze\\Desktop\\XMLFile2");
            dataGridView1.DataMember = "BookDetails";
            dataGridView1.DataSource = ds;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;


            MessageBox.Show("XML File created Successfully");

            catch (Exception ex)
Updated 15-May-12 8:57am

1 solution

Well, it looks like you create a new DataSet named ds, then write it to XML when it's still empty. Try filling the DataSet first, then write it to XML.
Share this answer
Sandeep Mewara 15-May-12 14:21pm    
Yep. 5!
Tooze 15-May-12 14:22pm    
Thank you THANK YOU THANK YOU. You just solved 6 hours of work, thank you so much!
Maciej Los 15-May-12 15:41pm    
Please, mark this question as "solved".
Maciej Los 15-May-12 15:37pm    
;) +5!
VJ Reddy 15-May-12 20:56pm    
Good answer. 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900