CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    5

    show data grid view of xml in C# form application

    <?xml version="1.0" encoding="utf-8" ?>
    <phonebook>

    <phone-number category = "family_relatives">

    <name> cathy </name>
    <number type = "vodafone"> 02698456</number>

    </phone-number>

    <phone-number category = "office">

    <name>MAPLE </name>
    <number>051235 </number>
    <address> MCIOEJAERJ</address>

    </phone-number>


    <phone-number category="peers">

    <name>15vregtre </name>
    <number>23154632165 </number>
    <address>klgirmfgj </address>
    <designation>klirglkfg </designation>

    </phone-number>


    </phonebook>
    ********************************************

    1. How to display the xml to data grid view in C# form application?
    2. How can we display type attribute in the grid view?

    Also, the code to read the xml file is not working, it does not show any error but do not display any o/p. I can't debug it.

    Can any one tell me the error
    **********************************************
    private void butLoad2_Click(object sender, EventArgs e)
    {
    XmlTextReader reader = new XmlTextReader("PhoneBookDirectory.xml");
    XmlNodeType type;

    while (reader.Read())
    {
    type = reader.NodeType;

    if (type == XmlNodeType.Element)
    {
    if (reader.Name == "phonebook")
    {
    reader.Read();
    textBox1.Text = reader.Value;
    }

    if (reader.Name == "phone-number")
    {
    reader.Read();
    listBox1.Items.Add(reader.Value);

    }

    }

    reader.Close();
    }
    }

  2. #2
    Join Date
    Nov 2011
    Posts
    5

    Re: show data grid view of xml in C# form application

    I do the code:
    *****************
    DataSet ds=new DataSet();
    ds.ReadXml("PhoneBookDirectory.xml");
    datagridview1.DataSource=ds.Tables(0);
    **********
    displays:
    the name datagridview1 does not exist in the current context
    Non-invocable member 'System.Data.DataSet.Tables' cannot be used like a method.
    *********************************************

    private void butLoad2_Click(object sender, EventArgs e)
    {
    DataSet myDatadSet=new DataSet();
    myDatadSet.ReadXml("PhoneBookDirectory.xml");
    dg1.DataSource=ds;
    dg1.Bind();
    ****************
    the name dg1 does not exist in the current context
    the name ds does not exist in the current context

    ************************************************************
    When I copied the full path of the xml file and put it in the code:

    myDatadSet.ReadXml("E:\projects\xml\practice\PhoneBook\PhoneBook\PhoneBookDirectory.xml");

    it showed:

    Unrecognized escape sequence
    ********************************
    Why is it so?

  3. #3
    Join Date
    Apr 2012
    Posts
    1

    Re: show data grid view of xml in C# form application

    myDatadSet.ReadXml("E:/projects/xml/practice/PhoneBook/PhoneBook/PhoneBookDirectory.xml");

    its help you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured