PC Review


Reply
Thread Tools Rate Thread

Datagrid - ReadXml

 
 
Raj Chudasama
Guest
Posts: n/a
 
      21st Sep 2005
I am trying to read an xml file and have it view data in the datagrid. (For
example take the xml file viewer in the visual studio, when u open an xml
file it has that nice readable grid).

I though that when i use the ReadXml funtion it will automatically read data
and add the data to the datagrid.

but i am wrong its not that simple. so i need help only with adding the data
to the datagrid.
this is what i have so far. I have created the grid with coulum names now i
need to add the rows of data. please help me thanks
private void CreateDataSet(string fileName)

{

DataSet newDataSet = new DataSet("New Data Set");

System.IO.FileStream readXml = new
System.IO.FileStream(fileName,System.IO.FileMode.Open);

newDataSet.ReadXml(readXml);

readXml.Close();

DataTable myTable = new DataTable("Mytable");

DataColumn cl1 = new DataColumn("Date");

DataColumn cl2 = new DataColumn("Device");

DataColumn cl3 = new DataColumn("call id");

DataColumn cl4 = new DataColumn("source");

DataColumn cl5 = new DataColumn("destination");

myTable.Columns.Add(cl1);

myTable.Columns.Add(cl2);

myTable.Columns.Add(cl3);

myTable.Columns.Add(cl4);

myTable.Columns.Add(cl5);


////////////// ADD ROWS HERE??????????////////

newDataSet.Tables.Add(myTable);


dataGrid1.SetDataBinding(newDataSet,"Mytable");

}


 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      21st Sep 2005
Raj,

This does probably what you want.
private void CreateDataSet(string fileName)
{
DataSet newDataSet = new DataSet();
newDataSet.ReadXml("FullPath");
dataGrid1.DataSource = newDataSet.Tables[0];
}

I hope this helps,

Cor


 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      21st Sep 2005
Oeps, I did not see you where passing the path


private void CreateDataSet(string fileName)
{
DataSet newDataSet = new DataSet();
newDataSet.ReadXml(fileName);
dataGrid1.DataSource = newDataSet.Tables[0];
}


 
Reply With Quote
 
Raj Chudasama
Guest
Posts: n/a
 
      21st Sep 2005
THANK YOU VERY MUCH Cor
it works

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Oeps, I did not see you where passing the path
>
>
> private void CreateDataSet(string fileName)
> {
> DataSet newDataSet = new DataSet();
> newDataSet.ReadXml(fileName);
> dataGrid1.DataSource = newDataSet.Tables[0];
> }
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help on ReadXml() John Microsoft C# .NET 4 12th Oct 2009 07:26 PM
ReadXml Tony Johansson Microsoft C# .NET 0 25th Aug 2008 08:25 AM
ReadXml Gerry Microsoft ADO .NET 0 28th Jul 2006 09:20 AM
Help with ReadXML Ryan Ramsey Microsoft C# .NET 1 17th Jun 2006 01:55 AM
DataGrid.ReadXml Xml->DataTable inference rules? KJ Microsoft C# .NET 0 9th Aug 2005 10:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:06 AM.