Click here to Skip to main content
14,447,974 members
Rate this:
Please Sign up or sign in to vote.
I am writing this code, but there is some error which i don't understand, can any body please help me to get out of this problem.
protected void Page_Load(object sender, EventArgs e)
{
  string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\abc\\My Documents\\Visual Studio 2005\\WebSites\\test\\App_Data\\test.mdb";
  OleDbConnection con = new OleDbConnection(connectionString);
  DataTable dt = new DataTable();
  //creating new connection to database Employee
  con.Open();
  //opening connection
  //assigning data to DataAdapter according to the query
  OleDbDataAdapter adpt = new OleDbDataAdapter("select * from emp", con);
  //filling dataset.
  adpt.Fill(dt);
  dt.WriteXml("test.xml");
  con.Close();
}
Thanks in advance.
Posted
Updated 5-Jul-11 1:22am
v2
Comments
Pete O'Hanlon 5-Jul-11 6:21am
   
What's the error? Some error isn't particularly helpful.
Prerak Patel 5-Jul-11 6:22am
   
Specify the exact error.
Joan M 5-Jul-11 6:25am
   
you should specify a little bit more... where do the error appears (which line) and which error appears... This information would help us to help you...
sahabiswarup 5-Jul-11 6:37am
   
dt.WriteXml("test.xml") InvalidOperationException was unhandled by user code
this is the error message
Wonde Tadesse 5-Jul-11 7:48am
   
Try to specify a full file path like dt.WriteXml("c:\\test.xml")
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hope this[^]might help you.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

If you are getting an InvalidOperationException, this means that one of the columns being serialized implements the interface IDynamicMetaObjectProvider but does not implement IXmlSerializable. There's very little you can do to circumvent this I'm afraid.
   
Comments
sahabiswarup 5-Jul-11 7:11am
   
what is your suggestion? what should i do?
Rate this:
Please Sign up or sign in to vote.

Solution 4

give the full xml file path

dt.WriteXml("test.xml");

above line should be like this
dt.WriteXml("C:\test.xml");


you can also go for full code:
http://www.authorcode.com/code-for-writing-xml-file-from-dataset-in-vb-net/[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100