ianinspain
asked on
500pts: My dataset (imported from XML) has an invalid Column - please help
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</VALUA TION>
</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].I temArray
{Length=5}
[0]: "COMPANY A"
[1]: "CBC456"
[2]: "928"
[3]: "19612222"
[4]: {0}
? myDataSet.Tables["Record"] .Columns[4 ].ColumnNa me
"Cartera_Id"
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</VALUA
</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"]
{Length=5}
[0]: "COMPANY A"
[1]: "CBC456"
[2]: "928"
[3]: "19612222"
[4]: {0}
? myDataSet.Tables["Record"]
"Cartera_Id"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and the contents of this new column/field is this
? myDataSet.Tables["Record"] .Columns[4 ].ColumnNa me
"CarteraDeBolsas_Id"
it is as if its trying to create an automatic ID/Key?? but unknown why ... and why its putting 0 in there
? myDataSet.Tables["Record"]
"CarteraDeBolsas_Id"
it is as if its trying to create an automatic ID/Key?? but unknown why ... and why its putting 0 in there
ASKER
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
Cheers
Ian
:-)
ASKER
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
76500</VALORACION></Record
VALOR>GAMESA</VALOR><ISIN>
<TITULOS>59900</TITULOS><V
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"]
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
}