Where I did this before with SQL Server 2000, I used OPENXML (as @EJB suggested), building an XML string in my code, passing it to the stored process in the text parameter using OPENXML to parse the XML in the relational structure and go from there, for example,
B. B.
Dim xmlStringBuilder As System.Text.StringBuilder xmlStringBuilder = New System.Text.StringBuilder xmlStringBuilder.Append("<objects>" For Each object In Collection 'I'm not suggesting this is the best way to build XML, it is however reliable! xmlStringBuilder.Append("<object id='" & object.id.ToString & "'></object>" Next xmlStringBuilder.Append("</objects>" Dim xmlStoredProcCommand As SqlCommand Dim xmlParameter As SqlParameter xmlStoredProcCommand = New SqlCommand(connection) xmlStoredProcCommand.CommandType = CommandType.StoredProcedure xmlStoredProcCommand.CommandText = "xmlStoredProc" xmlParameter = New SqlParameter("@xmlParameter",SqlDbType.NText) xmlParameter.Value = xmlStringBuilder.ToString xmlStoredProcCommand.Parameters.Add(xmlParameter) xmlStoredProcCommand.ExecuteNonQuery
SQL
CREATE PROCEDURE xmlStoredProc @xmlParameter NTEXT AS BEGIN DECLARE @xmldochandle INT DECLARE @objects TABLE (objectID INT) EXEC sp_xml_preparedocument @xmldochandle OUTPUT, @xmlParameter INSERT INTO @objects (objectId) SELECT objectId FROM OPENXML(@xmldochandle, 'objects/object') WITH (objectId INT) EXEC sp_xml_removedocument @xmldochandle END
and from there you can make your stuff with the contents of the @objects table variable.
source share