AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Brandon Drake
Expertise
I can answer questions regarding the Graphics object, file access, general optimization, printing (on paper), user controls, program mathematics, the registry, creating macros, processes, and fundamental or basic questions. I have made a few asp.net pages but I do not know the language extensively. I have not done much work with databases but I have created my own database systems.

Experience
I have been programming with visual basic for 6 years. In all I have written programs in about 8 programming languages, although, I only know about 3 well. I have written a few applications but mainly I like to write programs for fun.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > VB.NET and XML

Topic: VB.NET



Expert: Brandon Drake
Date: 7/4/2006
Subject: VB.NET and XML

Question
Hi Brandon,
I'm new to vb.net but am trying to extract data and save it in .xml format, the answer you gave to Ali's question helped me but I was just wondering what to declare the objMyAddresses as?

here is your answer to ali

Dear Ali,

Add a button to the form for the save button. The code for saving the data is very easy. You will want to let the users select a file by using the SaveFileDialog control. Add the SaveFileDialog control to your form to use the code below (I named mine "SaveFileDialog"). In the click event of the button put the code:

SaveFileDialog.Filter = "XML|*.xml"
SaveFileDialog.AddExtension = True
If SaveFileDialog.ShowDialog() = DialogResult.OK Then
objMyAddresses.WriteXml(SaveFileDialog.FileName, XmlWriteMode.WriteSchema)
End If

Some of the lines above may have been wrapped in the email so be careful. Next you will also want an "Open" button to open your database. Add the button and an OpenFileDialog control to allow the user to select the file. Use the following code in the open button's click event:

OpenFileDialog.Filter = "XML|*.xml"
If OpenFileDialog.ShowDialog = DialogResult.OK Then
objMyAddresses.ReadXml(OpenFileDialog.FileName, XmlReadMode.ReadSchema)
End If

The "Filter" property of these codes represents what files will be shown in the dialogs. So in this case only files ending in ".xml" will be shown.

Also, you probably want to add some code to allow the user to save if they close the application on accident without saving.


Yours hopefully,
Amanda  

Answer
Amanda,

The "objMyAddresses" is a DataSet which should be in the toolbox (where the buttons, textboxes, etc. are).  You can look that up in help to get more information.

Also, check out the System.XML namespace if you have not.  This has a whole lot of xml stuff.

I did a search of the internet and found an example using XML that may be helpful.  Here is the URL:

http://msdn.microsoft.com/vbasic/previous/2003/using/XML/default.aspx?pull=/libr...



Good Luck,

Brandon Drake

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.