示例:
.net
DataSet ds=....
string xml = ds.GetXml();
xml = xml.Replace("'","''");
SQL :
DECLARE @idoc int; EXEC sp_xml_preparedocument @idoc OUTPUT,
N'<User>\r\n
<Dept>\r\n
<ItemID>1</ItemID>\r\n
<EmpID>123</EmpID>\r\n
<Type>0</Type>\r\n
</Dept>\r\n
<Dept>\r\n
<ItemID>2</ItemID> \r\n
<EmpID>123</EmpID>\r\n
<Type>1</Type>\r\n
</Dept>\r\n
</User>';
INSERT INTO A (ItemID,EmpID,Type)
SELECT ItemID,EmpID,Type FROM OPENXML (@idoc, '/User/Dept',2)
WITH (ItemID int,EmpID nvarchar(50),Type int);