Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:06:30+00:00 2026-06-07T09:06:30+00:00

I have a stored procedure in SQL Server CREATE PROCEDURE ParseXML (@InputXML xml) The

  • 0

I have a stored procedure in SQL Server

CREATE PROCEDURE ParseXML (@InputXML xml)

The data type for input parameter is “xml”.

In the LINQ to SQL generated code for the stored procedure the input parameter is System.Xml.Linq.XElement

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.ParseXML")]
public ISingleResult<ParseXMLResult> ParseXML([global::System.Data.Linq.Mapping.ParameterAttribute(Name="InputXML", DbType="Xml")] System.Xml.Linq.XElement inputXML)

Now, how can I pass the following List to the ParseXML method to make the stored procedure work?

EDIT:

After reading the answer – another solution is listed below

XElement root = new XElement("ArrayOfBankAccountDTOForStatus",
new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"));


foreach (var element in bankAccountDTOList)
{

 XElement ex= new XElement("BankAccountDTOForStatus", 
                      new XElement("BankAccountID", element.BankAccountID),
                      new XElement("Status", element.Status));


 root.Add(ex);
} 

CODE In Question

        string connectionstring = "Data Source=.;Initial Catalog=LibraryReservationSystem;Integrated Security=True;Connect Timeout=30";
        var theDataContext = new DBML_Project.MyDataClassesDataContext(connectionstring);

        List<DTOLayer.BankAccountDTOForStatus> bankAccountDTOList = new List<DTOLayer.BankAccountDTOForStatus>();
        DTOLayer.BankAccountDTOForStatus presentAccount1 = new DTOLayer.BankAccountDTOForStatus();
        presentAccount1.BankAccountID = 5;
        presentAccount1.Status = "FrozenF13";

        DTOLayer.BankAccountDTOForStatus presentAccount2 = new DTOLayer.BankAccountDTOForStatus();
        presentAccount2.BankAccountID = 6;
        presentAccount2.Status = "FrozenF23";
        bankAccountDTOList.Add(presentAccount1);
        bankAccountDTOList.Add(presentAccount2);

        //theDataContext.ParseXML(inputXML);

Required XML Structure

enter image description here

Note: This XML is used for some operations, not for directly storing in database as XML. I need to write a select query that will list the data from the XML.

Stored Procedure Logic

DECLARE @MyTable TABLE (RowNumber int, BankAccountID int, StatusVal varchar(max))

INSERT INTO @MyTable(RowNumber, BankAccountID,StatusVal)

SELECT ROW_NUMBER() OVER(ORDER BY c.value('BankAccountID[1]','int') ASC) AS Row,
    c.value('BankAccountID[1]','int'),
    c.value('Status[1]','varchar(32)')
FROM
    @inputXML.nodes('//BankAccountDTOForStatus') T(c);

READING

  1. How to serialize and save an object to database as Xml using Linq to SQL

  2. How to use a LINQ query to get XElement values when XElements have same name

  3. Linq-to-SQL With XML Database Fields — Why does this work?

  4. http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=176385

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:06:31+00:00Added an answer on June 7, 2026 at 9:06 am

    You can turn your list into an XML fragment like this:

            IEnumerable<XElement> el = list.Select(i => 
                                new XElement("BankAccountDTOForStatus", 
                                  new XElement("BankAccountID", i.BankAccountID),
                                  new XElement("Status", i.Status)
                                ));
    

    Then you can turn it into an XElement:

            XElement root = new XElement("root", el);
    

    Now you can just pass it to ParseXML as parameter inputXML which is of type XElement.
    In stored procedure handle it like this:

    DECLARE @InputXML NVARCHAR(1024) = N'
    <root>
     <BankAccountDTOForStatus>
         <BankAccountID>2</BankAccountID>
         <Status>FrozenFA</Status>
     </BankAccountDTOForStatus>
     <BankAccountDTOForStatus>
         <BankAccountID>3</BankAccountID>
         <Status>FrozenSB</Status>
     </BankAccountDTOForStatus>
    </root>'
    
    DECLARE @handle INT
    
    EXEC sp_xml_preparedocument @handle OUTPUT, @InputXML
    
    SELECT  *
    FROM    OPENXML(@handle, '/root/BankAccountDTOForStatus', 1)
    WITH    (
                BankAccountID INT 'BankAccountID/text()',
                Status VARCHAR(128) 'Status/text()'
    )
    
    EXEC sp_xml_removedocument @handle
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recursive stored procedure on SQL Server. I'm using Linq-to-SQL generated classes, and
I have the following SQL Server stored procedure : BEGIN TRAN CREATE TABLE #TempTable
I have a stored procedure in SQL Server that returns some data via a
Using SQL Server 2008, I have two stored procedures - create procedure [dbo].[SH_Export_data] (@unit
I have the following sniplet of a stored procedure in SQL Server Create PROCEDURE
I have created a stored procedure in SQL Server 2005, also I create another
I have a stored procedure for select data between many different sql server, and
I have a stored procedure on SQL Server 2005. It is pulling from a
Let's say I have a stored procedure in Microsoft SQL Server 2005 that returns
I have the following stored procedure in an SQL Server 2005 database (meant simply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.