Using SQLXML Bulk Load in the. NET Environment

Source: Internet
Author: User
Tags ord

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.