Generating the XML with attributes using ADO.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amollokhande1
    New Member
    • Feb 2008
    • 33

    Generating the XML with attributes using ADO.net

    Hi,

    I am using the sqldataadapter for generating the output of query in the form of XML. I have following sample query

    select FirstName,LastN ame from Users where userid='Amol'

    After fetching the data using sqldataadapter, I got the result in following format

    <Dataset1>
    <Users>
    <FirstName>Amol </FirstName>
    <LastName>Lokha nde</LastName>
    </Users>
    </Dataset1>

    Now I would like to generate the xml in following format

    <Dataset1>
    <Users FirstName="Amol " LastName="Lokha nde"/>
    </Dataset1>

    Is there any setting for dataset or Sqldataadapter to generate the output in above format.

    Also I don't want to use Fox XML auto in the query

    Can anybody have solution on this?

    Regards
    Amol Lokhande
  • aryanbs
    New Member
    • Mar 2009
    • 42

    #2
    Try this way, suppose dt is datatable

    Code:
     For Each dc As DataColumn In dt.Columns
                dc.ColumnMapping = MappingType.Attribute
            Next
            dt.WriteXml("c:\backup\test.xml")

    Comment

    • amollokhande1
      New Member
      • Feb 2008
      • 33

      #3
      Hey Thanks a lot. It worked.

      Comment

      Working...