0

DataSet dset = new DataSet(); dset.ReadXml(FILENAME);

The error I got while Reading xml to dataset : Cannot add a SimpleContent column to a table containing element columns or nested relations.

I got to know what is causing the issue. My xml element that is causing issue looks something like below sample xml:(CreditCardDetail element is the one which is causing the issue as per my research on error. Also, this element data is not used later in our code so I need to somehow skip this element and load other elements data dynamically)

<PaymentData>
  <Amount/>
  <Change/>
  <CreditCardDetail i:nil="true"/>
</PaymentData>
<PaymentData>
  <Amount/>
  <Change/>
  <CreditCardDetail>
     <CardNumber i:nil="true"/>
     <Result i:nil="true"/>
  </CreditCardDetail>
</PaymentData>

I am trying to read the xml(which is not in our control) to dataset and then access the datatable to save the data into sql tables. But since the nested element like above is causing error I am not sure how to go futher. Can somebody please guide me any alternative solution.

1 Answers1

0

Problem is in CreditCardDetail. you have defined different structures for CreditCardDetail in the XML. It will fail for the second CreditCardDetail as it has already defined the SimpleContent for the XML. You can change the name of the second CreditCardDetail in your XML to something else.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • Yes.I get the problem is in CreditCardDetail but xml structure change is not controlled by us. For issue explanation I have showed it has reading from xml file but we get it as xml response from calling client soap api . My code to read xml response to dataset and then store to sql server using datatable was working fine until we started getting the CreditCardDetail element. I am new to c# programming so I am kind of struck at this point. – Spoorthi Tejasvi Nov 18 '21 at 09:39