borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (how to load form inside a picture box in vb 6.0)Next Topic (I could not delete the file) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Exporting Table from MS Accedd to XML using VB6
Poster Message
ahmad
Level: Master

Registered: 03-02-2003
Posts: 120

icon Exporting Table from MS Accedd to XML using VB6

Good Day

Can some one guide me that how can we transfer data from Ms Acess table to an XML File using VB6.

Regards


____________________________
@#@#@

24-07-2007 at 11:30 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Exporting Table from MS Accedd to XML using VB6

Open a recordset and save it to xml format (ADO 2.6+)

Dim rs As Recordset
    Dim db As ADODB.Connection
    
    Set rs = db.Execute("SELECT * FROM MyTable")
    rs.Save "c:\fred.xml", adPersistXML
    


Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

24-07-2007 at 03:30 PM
View Profile Send Email to User Show All Posts | Quote Reply
ahmad
Level: Master

Registered: 03-02-2003
Posts: 120
icon Re: Exporting Table from MS Accedd to XML using VB6

The output with rs.save is followig

***********OUTPUT*******************************
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:updatable='true'>
<s:AttributeType name='UserID' rs:number='1' rs:nullable='true' rs:maydefer='true' rs:writeunknown='true' rs:basetable='usr'
rs:basecolumn='UserID' rs:keycolumn='true'>
<s:datatype dt:type='string' dt:maxLength='10'/>
</s:AttributeType>
<s:AttributeType name='username' rs:number='2' rs:nullable='true' rs:maydefer='true' rs:writeunknown='true'
rs:basetable='usr' rs:basecolumn='username'>
<s:datatype dt:type='string' dt:maxLength='70'/>
</s:AttributeType>
<s:AttributeType name='Password' rs:number='3' rs:nullable='true' rs:maydefer='true' rs:writeunknown='true'
rs:basetable='usr' rs:basecolumn='Password'>
<s:datatype dt:type='string' dt:maxLength='20'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row UserID='admin' username='admin' Password=''/>
<z:row UserID='abc' username='xyz' Password='123'/>
</rs:data>
</xml>


But i only need fields name and Data

***************Required output************************
<xml
< UserID='admin' username='Admin' Password=''/>
< UserID='abc' username='xyz' Password='123' />
</xml>
**************************************************


[Edited by ahmad on 26-07-2007 at 11:37 AM GMT]

____________________________
@#@#@

26-07-2007 at 06:34 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Exporting Table from MS Accedd to XML using VB6

OK
This code will output xml from a recordset RS.


dim fout as integer
dim rs as recordset
dim fld as field

fout=freefile
open "c:\fred.xml" for output as fout

print #fout,"<XML>"
while not (rs.eof)
  print #fout, "<ROW ";
  for each fld in rs.fields
    print #fout, fld.name ; "="""; fld.value;""" "
  next fld
  print #fout, "/>"
  rs.movenext
wend
print #fout,"</XML>"

close fout


Note
This code will cause invalid XML if the fld.name has spaces in it, or the value contains reserved characters (like '<', qoutes, etc.)



[Edited by stickleprojects on 26-07-2007 at 08:17 AM GMT]

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

26-07-2007 at 08:17 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Exporting Table from MS Accedd to XML using VB6
Previous Topic (how to load form inside a picture box in vb 6.0)Next Topic (I could not delete the file) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder