Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,

I am converting xml to dataset but on server I am getting issues of can not find table 0 as I have checked it on local machine but didn't replicate it on here but on production I will get this error some times but not continuously. I am writing the lines that will convert xml to dataset. Please help to resolve the issue.

C#
String xmlString = loaddata;

                       System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlString));
                       reader.Read();

                       System.Data.DataSet dsData = new System.Data.DataSet();
                       dsData.ReadXml(reader, System.Data.XmlReadMode.Auto);
                       reader.Close();



Thanks,
Amit Mehan

What I have tried:

I have tried the below code as well but doesn't solve my issue..

C#
if (dsData.Tables.Count > 0)
                       {
                           if (dsData.Tables[0] == null)
                           {
                               reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlString));
                               reader.Read();

                               dsData = new System.Data.DataSet();
                               dsData.ReadXml(reader, System.Data.XmlReadMode.Auto);
                               reader.Close();
                           }
                       }
Posted
Updated 12-Apr-16 6:40am
v2
Comments
Sascha Lefèvre 12-Apr-16 9:50am    
Judging from the MSDN doc for the ReadXml-method (see here) you should use System.Data.XmlReadMode.ReadSchema instead of System.Data.XmlReadMode.Auto.

Also, I assume that you should remove the reader.Read(); line.
amit2620 12-Apr-16 10:20am    
By using System.Data.XmlReadMode.ReadSchema it is returning blank dataset.

1 solution

Hello ,
This is clear that your DataSet is blank or null .Hence it can not find any table . Modify your code like this way
if(dsData !=null && dsData.Tables.Count > 0)
{
//do other stuff
}

Thanks
 
Share this answer
 
Comments
Kats2512 13-Apr-16 3:30am    
5
Animesh Datta 13-Apr-16 8:49am    
Thanks :)

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