Hi Paul,
Here is an example, which I have prepared some time ago
Dim lcConnectionString As String
Dim loConnection As SqlClient.SqlConnection
Dim loDataAdapter As SqlClient.SqlDataAdapter
Dim loInsertCommand As SqlClient.SqlCommand
Dim loParameter As SqlClient.SqlParameter
Dim loDataSet As DataSet
Dim lnResult As Int32
Try
loDataSet = New DataSet()
loDataSet.ReadXml("E:\NET_Projects\XML_Batch\Products_30000.XML")
lcConnectionString = "Data Source='MYSERVER';" & _
"Initial Catalog=MYDB;Integrated
Security=SSPI;Pooling=False;" & _
"Connection Reset=False;"
loConnection = New SqlClient.SqlConnection(lcConnectionString)
loConnection.Open()
loInsertCommand = New
SqlClient.SqlCommand("usp_Batch_Insert", loConnection)
loInsertCommand.CommandType = CommandType.StoredProcedure
loParameter = loInsertCommand.Parameters.Add("@BATCH",
SqlDbType.Text)
loParameter.Value = loDataSet.GetXml()
lnResult = loInsertCommand.ExecuteNonQuery()
loParameter = Nothing
loInsertCommand.Dispose()
loInsertCommand = Nothing
loDataSet.Dispose()
loDataSet = Nothing
loConnection.Dispose()
loConnection = Nothing
Catch loE As Exception
MessageBox.Show(loE.Message)
End Try
CREATE PROCEDURE usp_Batch_Insert
@BATCH TEXT
AS
DECLARE @HDOC INT
EXEC sp_xml_preparedocument @HDOC OUTPUT, @BATCH
INSERT INTO Products
(ProductName,
SupplierID,
CategoryID,
QuantityPerUnit,
UnitPrice,
UnitsInStock,
UnitsOnOrder,
ReorderLevel,
Discontinued)
SELECT
ProductName,
SupplierID,
CategoryID,
QuantityPerUnit,
UnitPrice,
UnitsInStock,
UnitsOnOrder,
ReorderLevel,
Discontinued
FROM OPENXML (@HDOC, '/Products/Row',2)
WITH
(ProductName nvarchar(40),
SupplierID int,
CategoryID int,
QuantityPerUnit nvarchar(20),
UnitPrice money,
UnitsInStock smallint,
UnitsOnOrder smallint,
ReorderLevel smallint,
Discontinued bit)
EXEC sp_xml_removedocument @HDOC
RETURN