Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2006, 07:30 PM
ck ck is offline
Authorized User
 
Join Date: Dec 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Urgent ! Please Help....

hi, i am a beginner, do anyone how to store data into XML database using MS Visual C#.NET ??? example of my XML:

<Enrolment>
       <Name></Name>
       <Gender></Gender>
</Enrolment>

in my web interface, i got a button called "save", a textbox called "txtName", & a dropdownlist/combo box called "cboGender". so, after i enter (data) in all fields that i mentioned above(txtName, cboGender), then click the "save" button, it will store/save all the data that i enter into the XML database. in this program, it can't allow to use SQL connnection. i hope any expert can help me on this. below is my c# code:

private void cmdSave_Click(object sender, System.EventArgs e)
{
   DataSet ds = new DataSet();
   string filepath = @"C:\Documents and Settings\All
                     Users\Documents\Database.xml";
   FileStream findata = new FileStream
                    (filepath,FileMode.OpenOrCreate,FileAccess.Write,
                     FileShare.ReadWrite);
   ds.Tables["Enrolment"].Columns["FirstName"] = txtfname.Text;
   ds.WriteXml(findata);
   findata.Close();
}

P/s: i also dunno how to get the dropdownlist/combo box data & save it into XML database, because textbox property is .text, but combo box there are no .text.

i will appreciate if someone can help me....thanks a lot...

regards,


ck.
__________________
ck.
 
Old May 13th, 2006, 08:40 PM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

easier question first :)
P/s: i also dunno how to get the dropdownlist/combo box data & save it into XML database, because textbox property is .text, but combo box there are no .text.
well there is a property called as Items on combo box ;
so if ur control is named as combobox1, u can do combobox1.Items
and u can iterate using a foreach loop and get the required item.
For your first question try using XMLWriter / XMLReader class instead of Filestream.

 
Old May 15th, 2006, 08:11 PM
ck ck is offline
Authorized User
 
Join Date: Dec 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks, it work...:)

ck.
 
Old May 26th, 2006, 01:08 PM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

private void SaveData()
        {
            //Where is the xml data file?
            string tempFile = "DataFile.XML";

            //Open the XmlTextWriter
            XmlTextWriter tw = new XmlTextWriter(tempFile, null);
            //Open the File
            tw.WriteStartDocument();

            //Name the root element
            tw.WriteWhitespace("\n\t");
            tw.WriteStartElement("Enrolment");

            //First field 'Name'
            tw.WriteWhitespace("\n\t\t");
            tw.WriteStartElement("Name");
            tw.WriteString("George Washington");
            tw.WriteEndElement();

            //Next field 'Gender'
            tw.WriteWhitespace("\n\t\t");
            tw.WriteStartElement("Gender");
            tw.WriteString("Male");
            tw.WriteEndElement();

            //Close the file
            tw.WriteWhitespace("\n\t");
            tw.WriteEndDocument();
            //Close the TextWriter
            tw.Close();
        }

Notice the \n\t before each WriteString commands. This helps keep the XML file human compatible. If you never need to open the file up and look at it, using WordPad or another text editor, then you can omit these lines.

It is quite simple.

Happy Coding...






Similar Threads
Thread Thread Starter Forum Replies Last Post
urgent deb_kareng ASP.NET 2.0 Professional 1 August 13th, 2007 07:29 AM
it's urgent deb_kareng ASP.NET 2.0 Professional 3 August 7th, 2007 07:40 AM
urgent help yash_coolbuddy_forindia BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 May 7th, 2007 08:40 AM
urgent???????????? nsr35 Beginning VB 6 1 October 3rd, 2005 10:57 AM
urgent ??????????????? nsr35 Pro VB Databases 0 October 3rd, 2005 04:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.