Salvestatud protseduur ise
ALTER PROCEDURE [dbo].[HOUSE_DEP_KUIDO_U]
@teenuse_id NCHAR(5),
@genarved XML=NULL OUTPUT --seda tahame kätte saada
--siin annab @genarved muutujale väärtuse
DECLARE @arved TABLE (account_id BIGINT PRIMARY KEY)
INSERT INTO @arved (account_id) VALUES(13)
INSERT INTO @arved (account_id) VALUES(12)
SET @genarved = ( SELECT account_id AS 'Invoice/@InvoiceId' FROM @arved FOR XML PATH(''), TYPE, ROOT('Invoices') )
tulemus on SQL-is XML-ina on
<Invoices>
<Invoice InvoiceId="12" />
<Invoice InvoiceId="13" />
</Invoices>
Antud asja ADO.NET-is kasutamine
using System.Data.SqlClient;
using System.Xml;
using System.Data;
using (SqlConnection konn = new SqlConnection(Configuration.ConnectionString))
{
SqlCommand komm = new SqlCommand("[dbo].[HOUSE_DEP_KUIDO_U]", konn);
komm.CommandType = CommandType.StoredProcedure;
// siin tuleb SqlDbType.Xml tüübi suuruseks panna positiivne arv ja määrab ka et on tagastatav parameeter
komm.Parameters.Add("@genarved", SqlDbType.Xml,8).Direction = ParameterDirection.InputOutput;
konn.Open();
komm.ExecuteNonQuery();
}
//XML muutuja lugemine ADO.NET XmlDocument objekti
XmlDocument kort = new XmlDocument();
kort.LoadXml(komm.Parameters["@genarved"].Value.ToString().Trim());
Blogged with the Flock Browser