Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


Step-1: Create table in which you want to load XML file

Click here to copy the following block
create database MyDB
go
USE MyDB
go
CREATE TABLE Customer (
  CustomerId INT PRIMARY KEY,
  CompanyName NVARCHAR(20),
  City NVARCHAR(20))
go
--After insert run this
select * from Customer

Step-2: create xml file - customers.xml

Click here to copy the following block
<ROOT>
 <Customers>
  <CustomerId>1111</CustomerId>
  <CompanyName>Sean Chai</CompanyName>
  <City>NY</City>
 </Customers>
 <Customers>
  <CustomerId>1112</CustomerId>
  <CompanyName>Tom Johnston</CompanyName>
  <City>LA</City>
 </Customers>
 <Customers>
  <CustomerId>1113</CustomerId>
  <CompanyName>Institute of Art</CompanyName>
 </Customers>
</ROOT>

Step-3: create xml schema file for validation - customermapping.xsd

Click here to copy the following block
<?xml version="1.0" ?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
    xmlns:dt="urn:schemas-microsoft-com:xml:datatypes" 
    xmlns:sql="urn:schemas-microsoft-com:xml-sql" >

  <ElementType name="CustomerId" dt:type="int" />
  <ElementType name="CompanyName" dt:type="string" />
  <ElementType name="City" dt:type="string" />

  <ElementType name="ROOT" sql:is-constant="1">
   <element type="Customers" />
  </ElementType>

  <ElementType name="Customers" sql:relation="Customer">
   <element type="CustomerId" sql:field="CustomerId" />
   <element type="CompanyName" sql:field="CompanyName" />
   <element type="City"    sql:field="City" />
  </ElementType>
</Schema>

Step-4: create following vbscript file in notepad - name it insert_xml_data.vbs

Click here to copy the following block
Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad")
objBL.ConnectionString = "provider=SQLOLEDB.1;data source=(local);database=MyDB;uid=etl;pwd=etl"
objBL.ErrorLogFile = "c:\error.log"
objBL.Execute "c:\customermapping.xsd", "c:\customers.xml"
Set objBL = Nothing

Finally double click saved vbs file to execute.


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.