Click here to Skip to main content
15,880,905 members
Articles / Programming Languages / C#

Saving Master-Details form using XML

Rate me:
Please Sign up or sign in to vote.
4.83/5 (10 votes)
14 Apr 20042 min read 69.9K   1.4K   41  
This article shows how to save a master-details form using XML.
CREATE TABLE Purchase (
	InvoiceID numeric(18, 0) NOT NULL IDENTITY (1, 1),
	InvoiceDate datetime NOT NULL,
	SupplierName varchar(50) NULL
) 
GO

CREATE TABLE PurchaseDetails (
	InvoiceID int NOT NULL ,
	[Description] varchar (75) NOT NULL ,
	Quantity int NOT NULL ,
	Rate numeric(18, 2) NOT NULL ,
	Amount numeric(18, 2) NOT NULL 
)
GO
CREATE PROC InsertPurchaseOrder (@InvoiceDate DATETIME, @SupplierName VARCHAR(50), @PurchaseDetails NTEXT)
AS
BEGIN
 	DECLARE @InvoiceID INT
 	DECLARE @idoc INT

	INSERT INTO Purchase( InvoiceDate, SupplierName)
 	VALUES (@InvoiceDate, @SupplierName)

 	SET @InvoiceID = @@IDENTITY

	-- Create an internal representation of the XML document.
	EXEC sp_xml_preparedocument @idoc OUTPUT, @PurchaseDetails
	-- Insert the values in the details table
	INSERT PurchaseDetails (InvoiceID, [Description], Quantity, Rate, Amount)
	SELECT @InvoiceID, [Description], Quantity, Rate, Amount
	FROM OPENXML (@idoc, '/PurchaseOrder/Details', 2)
	WITH PurchaseDetails
	-- Destory the internal representation of the XML document.
	EXEC sp_xml_removedocument @idoc
END

GO

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Arab Emirates United Arab Emirates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions