Feroz Khan

Feroz Khan

  • 1.4k
  • 300
  • 91.9k

How to Read Xml in DataTable or DataSet

Jun 13 2018 9:03 PM
Hi,
 
I am trying to use read xml file in dataset but showing some error i want to read same file in dataset, can anyone help me for this.
 
below is my code..
  1. XmlReader xmlFile;  
  2. xmlFile = XmlReader.Create(@"C:\Users\Feroz\Desktop\xml Data\file.xml"new XmlReaderSettings());  
  3. DataSet ds = new DataSet("tbl");  
  4. ds.ReadXml(xmlFile);  
  5. int i = 0;  
  6. for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)  
  7. {  
  8. MessageBox.Show(ds.Tables[0].Rows[i].ItemArray[2].ToString());  
  9. }  
showing error - Column name 'lWorkstationNmbr' is defined for different mapping types.
xml file. 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <ITX_CLOSE_EXPORT>  
  3. <STORE_INFO>  
  4. <storeId>6644</storeId>  
  5. <closeDate>20180401</closeDate>  
  6. <sessionDateFrom>20180331</sessionDateFrom>  
  7. <sessionTimeFrom>220334</sessionTimeFrom>  
  8. <sessionDateTo>20180401</sessionDateTo>  
  9. <sessionTimeTo>221204</sessionTimeTo>  
  10. <version>3.5.4.1</version>  
  11. </STORE_INFO>  
  12. <VALID_TICKETS>  
  13. -<SALE_LINE_ITEMS>  
  14. -<ITEM lTaNmbr="2915" lWorkstationNmbr="1" lRetailStoreId="6644">  
  15. <lRetailStoreID>6644</lRetailStoreID>  
  16. <lWorkstationNmbr>1</lWorkstationNmbr>  
  17. <lTaNmbr>2915</lTaNmbr>  
  18. <szItxOperationType>1</szItxOperationType>  
  19. <szItxSerial>S</szItxSerial>  
  20. <lItxCurrentValue>1367</lItxCurrentValue>  
  21. <szDate>20180401</szDate>  
  22. <szTime>112629</szTime>  
  23. <lOperatorID>11532</lOperatorID>  
  24. <lItxLineNmbr>1</lItxLineNmbr>  
  25. <szItemLookupCode>4844001370632</szItemLookupCode>  
  26. <lItxYear>2018</lItxYear>  
  27. <szItxCampaign>V</szItxCampaign>  
  28. <lItxFamilyCode>92</lItxFamilyCode>  
  29. <lItxSubFamilyCode>102</lItxSubFamilyCode>  
  30. <szItxPeriodDesc>S</szItxPeriodDesc>  
  31. <szMerchHierarchyLevelCode>1</szMerchHierarchyLevelCode>  
  32. <dTaQty>1.0000</dTaQty>  
  33. <dTaPrice>17.0000</dTaPrice>  
  34. <dOrgPrice>0.0000</dOrgPrice>  
  35. <dTaDiscount>0.0000</dTaDiscount>  
  36. <dItxTaxPercent>18.0000</dItxTaxPercent>  
  37. <bIsVoidReceiptSLI>0</bIsVoidReceiptSLI>  
  38. <szType>ART_SALE</szType>  
  39. <szTaType>SA</szTaType>  
  40. <lItxOriginalRetailStoreID>0</lItxOriginalRetailStoreID>  
  41. <lItxOriginalWorkstationNmbr>0</lItxOriginalWorkstationNmbr>  
  42. <lItxOriginalTaNmbr>0</lItxOriginalTaNmbr>  
  43. <lItxOriginalCurrentValue>0</lItxOriginalCurrentValue>  
  44. <szItxOriginalSerial>0</szItxOriginalSerial>  
  45. <szItxOriginalDate>0</szItxOriginalDate>  
  46. <szEmployeeNumber>-1</szEmployeeNumber>  
  47. </ITEM>  

Answers (10)