2 Replies - 7356 Views - Last Post: 09 January 2012 - 03:39 PM Rate Topic: -----

#1 jone kim  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 07-January 10

data grid view of xml file in C# form application

Posted 09 January 2012 - 03:17 PM

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

  <phone-number category = "family_relatives">
    
    <name> cathy </name>
    <number type = "vodafone"> 9804423599</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>



************************
How to view this xml file via data grid view in C# form application?
I did it in the way:
****************************
DataSet ds=new DataSet();
ds.ReadXml("PhoneBookDirectory.xml");
datagridview1.DataSource=ds.Tables(0);


************************
ERROR:
the name datagridview1 does not exist in the current context
Non-invocable member 'System.Data.DataSet.Tables' cannot be used like a method.

************************
ds.ReadXml("Yourfilepath");
ds.ReadXml("E:\projects\xml\practice\PhoneBook\PhoneBook\PhoneBookDirectory.xml");  


when I copied the full path from the xml file, it shows the error:
Unrecognized escape sequence
**********************************
What is the problem?

Is This A Good Question/Topic? 0
  • +

Replies To: data grid view of xml file in C# form application

#2 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 182
  • View blog
  • Posts: 783
  • Joined: 27-October 11

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

Posted 09 January 2012 - 03:34 PM

For the first set of errors:
Check if put the dataGridView control on the form.
Throw out the '(0)' part after the .Tables. It isn't a method therefore you can't pass arguments to it. Instead of that user indexers: [0]

For the second error:
Use double '\' for supplying the location of the file.
Was This Post Helpful? 0
  • +
  • -

#3 negligible  Icon User is offline

  • D.I.C Regular

Reputation: 62
  • View blog
  • Posts: 302
  • Joined: 02-December 10

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

Posted 09 January 2012 - 03:39 PM

Every code code has an entry on the MSDN about what can cause it, this is the first place you should look any time you get a error code or an exception you don't know.

I searched for "Unrecognized escape sequence" MSDN in google and the first page has the answer.

http://msdn.microsof...3(v=vs.80).aspx

Quote

1
[b]DataSet ds=new DataSet();[/b]
2
ds.ReadXml("PhoneBookDirectory.xml");
3
datagridview1.DataSource=[b]ds.Tables(0)[/b];


************************
ERROR:
the name datagridview1 does not exist in the current context
Non-invocable member 'System.Data.DataSet.Tables' cannot be used like a method.

I have put the relevant parts in bold.
edit: Oh right, of course that wouldn't work, well just look where the BB code tags are.

ds.tables is a property. You have tried to use it as a method like so ds.Tables(0), it can't be used like that as the error says.

You can "get" or "set" a property.

//Getting the DataSet Type value from ds.Tables. In other words, referencing it as "getProperty".
var getProperty = ds.Tables;

//Setting the Tables property
ds.Tables = dataToSetInTable;

This post has been edited by negligible: 09 January 2012 - 03:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1