Thursday, September 28, 2006

Dump XML output to a file

'colName is hard-coded here

Dim MyConn, SQL_query,ResultSet,myName

'Open database connection
Set MyConn = CreateObject("ADODB.Connection")
MyConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\sangeeta\emp.mdb"

'Define the SQL query
SQL_query = "SELECT emp_name FROM employee"

'Execute the query and store results in ResultSet
Set ResultSet = MyConn.Execute(SQL_query)
ResultSet.MoveFirst

Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line with a newline character.
tf.WriteLine("<xml>")

'Read results from ResultSet in a loop
While NOT ResultSet.EOF
Set name1 = ResultSet("emp_name")
tf.WriteLine(addXmlTag("emp_name",name1))
ResultSet.MoveNext
WEND
tf.WriteLine("</xml>")

'Release resources
ResultSet.close
MyConn.close

Function addXmlTag(colName,colValue)
startTag ="<" endTag=">"
addXmlTag = startTag & colName & endTag & colValue & startTag & "/" & colName & endTag
End Function

7 Comments:

Blogger Samatajulli said...

In the site was very excellent,i think this is very best one compare others and then the more information to get after read this post.

SAP training in Chennai

5:27 AM  
Blogger Keerthi said...


Good post. I learn something totally new and challenging on blogs I stumble upon on a daily basis. It will always be interesting to read articles from other authors and practice something from their websites...

Corporate Training in Chennai

2:39 AM  
Blogger Aasha said...

I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

Digital Marketing Company in Chennai
Digital Marketing Services in Chennai

1:58 AM  
Blogger prethikarajesh said...

Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
digital marketing company in chennai

3:44 AM  
Blogger karthireva said...


This content creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this.


Best Dot Net institutes in chennai

12:29 AM  
Anonymous Anonymous said...

Provides great information about the concept.It helps an individual to gain knowledge on new techniques.Keep on giving this type of information.
SEO company in Chennai

3:57 AM  
Blogger Nikisha said...

Great.Nice information.It is more useful and knowledgeable. Thanks for sharing keep going on.. and I expect more blog like this
Digital Marketing Company in India
Seo Company in India

2:12 AM  

Post a Comment

<< Home