Debugging DataSet.ReadXML()

G

Guest

Hello,

I am using the ReadXML function of the DataSet to read in an xml file into a dataset after I called fillSchema on the tables that will be loaded into the dataset. I have been able to get this working in the past but I often have a very, very difficult time debugging the ReadXML function. It tends to give me errors like

input string was not in a correct format or failed to enable constraints.

It doesnt bother to tell me what string or what field or even what line number of my xml file is causing the problem. Is there any way to get this information. Can I get some output that tells me where in my xml file ReadXml is failing?
 
O

Oleg Ogurok

See MSDN docs on DataSet.HasErrors and DataTable.GetErrors()

-Oleg.

ryanul said:
Hello,

I am using the ReadXML function of the DataSet to read in an xml file into
a dataset after I called fillSchema on the tables that will be loaded into
the dataset. I have been able to get this working in the past but I often
have a very, very difficult time debugging the ReadXML function. It tends
to give me errors like
input string was not in a correct format or failed to enable constraints.

It doesnt bother to tell me what string or what field or even what line
number of my xml file is causing the problem. Is there any way to get this
information. Can I get some output that tells me where in my xml file
ReadXml is failing?
 
G

Guest

Thank you very much for your response. I hadn't thought of using getErrors(). I tried what you suggested and called hasErrors on the dataset after the readxml function failed and hasErrors returned false. I checked for errors in the exception handler for the function that calls readxml(). I get an exception of course but I would like more info on where the error occured in the dataset loading. If hasErrors and GetErrors does that for me that would be great. I was under the impression that GetErrors returned row errors for rows where I set the errors manually. If this is so, are you suggesting I set the errors for rows that have problems and if so, how would I do that inside the readxml function? Is there some sort of flag that enables .NET error settings for rows that I can read out later with GetErrors()? Right now I am doing this.

class myDataSet : DataSet
// other code
public void fillDataset()
try
{
// call fillSchema on each table to prepare the dataset and then readxml.
readXML("input.xml");
}
catch ( Exception ex)
{
if ( this.HasErrors == true )
{
foreach(DataTable myTable in this.Tables)
{
foreach(DataRow myRow in myTable.Rows)
{
if(myRow.HasErrors)
{
Console.WriteLine(myRow.RowError);
}
}
}
}

Thanks

Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top