Solved

500pts: My dataset (imported from XML) has an invalid Column - please help

Posted on 2006-06-22
5
206 Views
Last Modified: 2010-04-16
Hi there,

Can anyone help?

I have imported an xml file into a dataset using ReadXML method. And it has worked, but its invented a new columnn name. So i am having problems binding it to a grid.

I don't understand why its invented a new column name... i would appreciate any input .. Thanks in advance...

Here a portion of the xml file...  as you can see .. there is a total of 4 columns
- <Cartera>
- <Record>
  <VAL>COMPANY A</VAL>
  <E>CBC456</E>
  <TI>928</TI>
  <VALUATION>19612222</VALUATION>
  </Record>
etc ,.... etc.....

Here is me printing out the values of the table in DEBUG - see number [4] it shouldn't be there, it is of course present in ALL rows and seems to equal {0} in all rows...
? myDataSet.Tables["Record"].Rows[5].ItemArray
{Length=5}
    [0]: "COMPANY A"
    [1]: "CBC456"
    [2]: "928"
    [3]: "19612222"
    [4]: {0}

? myDataSet.Tables["Record"].Columns[4].ColumnName
"Cartera_Id"
0
Comment
Question by:ianinspain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
rinksno1 earned 500 total points
ID: 16958490
string xmlfilepath = @"C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\XMLFile1.xml";
            DataSet ds = new DataSet();
            ds.ReadXml(xmlfilepath);

            DataTable dtbl = ds.Tables[0];
            foreach (DataRow dr in dtbl.Rows)
            {
                Console.WriteLine(dr[0]);
                Console.WriteLine(dr[1]);
                Console.WriteLine(dr[2]);
                Console.WriteLine(dr[3]);
           
            }
            Console.ReadLine();

I did the above code on your xml but it is running perfect whenever i try to do dr[4] it gives me an error that column 4 not found...

thanks
rinks
0
 

Author Comment

by:ianinspain
ID: 16958546
Thanks rinksno1.. ermmm very strange... thanks for offering help here as it has me beat!! It is much appreciated.

I just did the same, and i still got number 4 :-) Maybe it will help if i show you more code and the real XML file rather than an example/portion?

All below is actual real data.

I changed your test a little and got this in the Console output

REPSOL YPF
ES0173516115
92845
1959029.50
0   /// THIS ISN'T on the XML file

my code below... is complete ... Get CarteraBolsas is a method that calls WebService that i wrote which returns XmlNode

the contents on tester.OuterXML - I copied and pasted it in the Command window..
? tester.OuterXml
"<response xmlns=\"\"><Error code=\"0\" description=\"OK\" /><CarteraDeBolsas><Record><VALOR>REPSOL YPF</VALOR><ISIN>ES0173516115</ISIN><TITULOS>92845</TITULOS><VALORACION>1959029.50</VALORACION></Record><Record><VALOR>FERROVIAL</VALOR><ISIN>ES0162601019</ISIN><TITULOS>19000</TITULOS><VALORACION>1091550</VALORACION></Record><Record><VALOR>GR.EMP.ENCE</VALOR><ISIN>ES0130625017</ISIN><TITULOS>39546</TITULOS><VALORACION>1166607</VALORACION></Record><Record><VALOR>ABENGOA</VALOR><ISIN>ES0105200416</ISIN><TITULOS>4000</TITULOS><VALORACION>74760</VALORACION></Record><Record><VALOR>BSCH</VALOR><ISIN>ES0113900J37</ISIN><TITULOS>429243</TITULOS><VALORACION>4700210.85</VALORACION></Record><Record><VALOR>ENDESA</VALOR><ISIN>ES0130670112</ISIN><TITULOS>124735</TITULOS><VALORACION>3319198.35</VALORACION></Record><Record><VALOR>ZELTIA</VALOR><ISIN>ES0184940817</ISIN><TITULOS>287208</TITULOS><VALORACION>1619853.12</VALORACION></Record><Record><VALOR>CEPSA</VALOR><ISIN>ES0132580319</ISIN><TITULOS>23000</TITULOS><VALORACION>12
76500</VALORACION></Record><Record><VALOR>BA.POPULAR</VALOR><ISIN>ES0113790531</ISIN><TITULOS>192039</TITULOS><VALORACION>2168120.31</VALORACION></Record><Record><VALOR>SOGECABLE</VALOR><ISIN>ES0178483139</ISIN><TITULOS>107624</TITULOS><VALORACION>2369880.48</VALORACION></Record><Record><VALOR>IBERDROLA</VALOR><ISIN>ES0144580018</ISIN><TITULOS>69000</TITULOS><VALORACION>1797450</VALORACION></Record><Record><VALOR>UNION FENOSA</VALOR><ISIN>ES0181380017</ISIN><TITULOS>25626</TITULOS><VALORACION>774673.98</VALORACION></Record><Record><VALOR>BANESTO</VALOR><ISIN>ES0113440038</ISIN><TITULOS>77560</TITULOS><VALORACION>1059469.60</VALORACION></Record><Record><VALOR>ARCELOR</VALOR><ISIN>LU0140205948</ISIN><TITULOS>30553</TITULOS><VALORACION>1073937.95</VALORACION></Record><Record><VALOR>BBVA</VALOR><ISIN>ES0113211835</ISIN><TITULOS>245443</TITULOS><VALORACION>3826456.37</VALORACION></Record><Record><VALOR>PRISA</VALOR><ISIN>ES0171743117</ISIN><TITULOS>60861</TITULOS><VALORACION>746764.47</VALORACION></Record><Record><
VALOR>GAMESA</VALOR><ISIN>ES0143416115</ISIN><TITULOS>30785</TITULOS><VALORACION>487326.55</VALORACION></Record><Record><VALOR>ALTADIS</VALOR><ISIN>ES0177040013</ISIN><TITULOS>55958</TITULOS><VALORACION>2044705.32</VALORACION></Record><Record><VALOR>ERCROS</VALOR><ISIN>ES0125140014</ISIN><TITULOS>1575143</TITULOS><VALORACION>992340.09</VALORACION></Record><Record><VALOR>OHL</VALOR><ISIN>ES0142090317</ISIN><TITULOS>24198</TITULOS><VALORACION>354016.74</VALORACION></Record><Record><VALOR>ACERINOX</VALOR><ISIN>ES0132105018</ISIN><TITULOS>151229</TITULOS><VALORACION>1979587.61</VALORACION></Record><Record><VALOR>FADESA</VALOR><ISIN>ES0135961219</ISIN><TITULOS>17800</TITULOS><VALORACION>449272</VALORACION></Record><Record><VALOR>LA SEDA BAR.</VALOR><ISIN>ES0175290115</ISIN><TITULOS>436034</TITULOS><VALORACION>967995.48</VALORACION></Record><Record><VALOR>INDRA A</VALOR><ISIN>ES0118594417</ISIN><TITULOS>125798</TITULOS><VALORACION>1937289.20</VALORACION></Record><Record><VALOR>CINTRA</VALOR><ISIN>ES0118900010</ISIN>
<TITULOS>59900</TITULOS><VALORACION>589416</VALORACION></Record><Record><VALOR>TELEFONICA</VALOR><ISIN>ES0178430E18</ISIN><TITULOS>384933</TITULOS><VALORACION>4981033.02</VALORACION></Record><Record><VALOR>INM.URBIS</VALOR><ISIN>ES0154800215</ISIN><TITULOS>48790</TITULOS><VALORACION>938231.70</VALORACION></Record><Record><VALOR>COR.MAPFRE</VALOR><ISIN>ES0124244C36</ISIN><TITULOS>72015</TITULOS><VALORACION>1053579.45</VALORACION></Record><Record><VALOR>BANKINTER</VALOR><ISIN>ES0113679338</ISIN><TITULOS>18784</TITULOS><VALORACION>910084.80</VALORACION></Record><Record><VALOR>METROVACESA</VALOR><ISIN>ES0154220414</ISIN><TITULOS>50</TITULOS><VALORACION>3712.50</VALORACION></Record><Record><VALOR>ACS</VALOR><ISIN>ES0167050915</ISIN><TITULOS>49562</TITULOS><VALORACION>1555255.56</VALORACION></Record></CarteraDeBolsas></response>"

and my code
                  DataSet myDataSet = new DataSet();

                  XmlNode tester = GetCarteraBolsas(); // this is a method that calls a webservice


                  XmlNodeReader testme = new XmlNodeReader(tester);


                  
                  myDataSet.ReadXml(testme);


                  DataTable dtbl = myDataSet.Tables["Record"]; // I need to ask for "Record" as my dataset contains more tables i.e. the Error table
                  foreach (DataRow dr in dtbl.Rows)
                  {
                        Console.WriteLine(dr[0]);
                        Console.WriteLine(dr[1]);
                        Console.WriteLine(dr[2]);
                        Console.WriteLine(dr[3]);
                        Console.WriteLine(dr[4]); //this still returns 0
           
                  }
0
 

Author Comment

by:ianinspain
ID: 16958558
and the contents of this new column/field is this

? myDataSet.Tables["Record"].Columns[4].ColumnName
"CarteraDeBolsas_Id"

it is as if its trying to create an automatic ID/Key?? but unknown why ... and why its putting 0 in there

0
 

Author Comment

by:ianinspain
ID: 16958647
Don't worry i got it going now... don't know what it was.. but your test helped so i am going to assign points

Cheers

Ian
0
 
LVL 3

Expert Comment

by:rinksno1
ID: 16958672
:-)
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question