Http://msdn.microsoft.com/en-us/library/ms171878.aspx
1. First create a table
CREATE TABLEOrd (OrderIDint Identity(1,1)PRIMARY KEY, CustomerIDvarchar(5))GOCREATE TABLEProduct (ProductIDint Identity(1,1)PRIMARY KEY, ProductNamevarchar( -))GOCREATE TABLEOrderDetail (OrderIDint FOREIGN KEY REFERENCESOrd (OrderID), ProductIDint FOREIGN KEY REFERENCESProduct (ProductID),CONSTRAINTOd_keyPRIMARY KEY(OrderID, ProductID))GO
2. Save an XML file Schema.xml
<Xsd:schemaxmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:sql= "Urn:schemas-microsoft-com:mapping-schema"><xsd:annotation> <Xsd:appinfo> <sql:relationshipname= "Orderod"Parent= "Ord"Parent-key= "OrderID" Child= "OrderDetail"Child-key= "OrderID" /> <sql:relationshipname= "Odproduct"Parent= "OrderDetail"Parent-key= "ProductID" Child= "Product"Child-key= "ProductID"Inverse= "true"/> </Xsd:appinfo></xsd:annotation> <xsd:elementname= "Order"sql:relation= "Ord"Sql:key-fields= "OrderID" > <Xsd:complextype> <xsd:sequence> <xsd:elementname= "Product"sql:relation= "Product"Sql:key-fields= "ProductID"sql:relationship= "Orderod odproduct"> <Xsd:complextype> <Xsd:attributename= "ProductID"type= "Xsd:int" /> <Xsd:attributename= "ProductName"type= "Xsd:string" /> </Xsd:complextype> </xsd:element> </xsd:sequence> <Xsd:attributename= "OrderID"type= "Xsd:integer" /> <Xsd:attributename= "CustomerID"type= "Xsd:string" /> </Xsd:complextype> </xsd:element></Xsd:schema>
3. Save another XML file Data.xml
<ROOT> <OrderOrderID= "One"CustomerID= "ALFKI"> <ProductProductID= "One"ProductName= "Chai" /> <ProductProductID= "All"ProductName= "Chang" /> </Order> <OrderOrderID= "All"CustomerID= "Anatr"> <ProductProductID= " the"ProductName= "Aniseed Syrup" /> <ProductProductID= "$"ProductName= "Gumbo Mix" /> </Order></ROOT>
4. Open VS, create a console application
5. Add DLL reference in the COM tab, select Microsoft SQLXML bulkload 4.0 Type Library (xblkld4.dll) and click OK. You'll see the Interop.sqlxmlbulkloadlib assembly created in the project.
Dad, I can't find xblkld4.dll C:\Program files\common Files\System\Ole Db\xblkld4.dll on my computer.
This DLL is not found in the corresponding directory in the program files and Program Files folder of my Computer x86
The 6.Main function is as follows
Static voidMain (string[] args) { Try{Sqlxmlbulkloadlib.sqlxmlbulkload4class OBJBL=NewSqlxmlbulkloadlib.sqlxmlbulkload4class (); objBL.ConnectionString="provider=sqloledb;server=server;database=databasename;integrated Security=sspi"; Objbl.errorlogfile="Error.xml"; Objbl.keepidentity=false; Objbl.execute ("Schema.xml","Data.xml"); } Catch(Exception e) {Console.WriteLine (e.tostring ()); } }
Using SQLXML Bulk Load in the. NET Environment