'Making Xml
Dim sb As New System.Text.StringBuilder
sb.Append("")
For i = 0 To dt.Rows.Count - 1
sb.Append("
sb.Append("PQty=""" & dt.Rows(i).Item("PQty") & """")
sb.Append("PWeight=""" & ClearWhiteSpace(dt.Rows(i).Item("PWeight")) & """")
sb.Append("/>")
Next
sb.Append("")
-- Making Stored Procedure
CREATE PROCEDURE [dbo].[TestMasterInsert]
@MId Int,
@GId Int,
@PId Int,
@Name varchar(50),
@Data text,
@TranType Char(1)
AS
BEGIN
SET NOCOUNT ON;
Declare @id As Int
SET @id = 0
DECLARE @hDoc int exec sp_xml_preparedocument @hDoc OUTPUT, @Data
IF @TranType = 'I'
BEGIN
Insert Into TestMaster Values (@GId,@PId,@Name)
Select @id = SCOPE_IDENTITY()
INSERT INTO TestDetail
SELECT @id,PQty,PWeight
FROM OPENXML (@hDoc, '/ROOT/SI',2)
WITH (
PQty Decimal(18,3) '@PQty',
PWeight Decimal(18,3) '@PWeight'
)
EXEC sp_xml_removedocument @hDoc
END
ELSE IF @TranType = 'U'
BEGIN
UPDATE TestDetail
SET
TestDetail.PQty = XMLTEST.PQty,
TestDetail.PWeight = XMLTEST.PWeight
FROM OPENXML(@hDoc, '/ROOT/SI',2)
WITH (DId Int '@DId',PQty Decimal(18,3) '@PQty',PWeight Decimal(18,3) '@PWeight') XMLTEST
WHERE TestDetail.DId = XMLTEST.DId
EXEC sp_xml_removedocument @hDoc
END
END