-
January 9th, 2012, 11:02 AM
#1
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();
}
}
-
January 9th, 2012, 05:06 PM
#2
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?
-
April 16th, 2012, 12:32 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|