Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have xml data as given bellow
i am trying to fill dataset from xml string not xml file and i want to convert above xml to datset / datatable
HTML
<reportdata>
  <columns day="Thrusday" date="12/1/2011 12:00:00 AM">
    <column name="cDATA" calculated="0" formula="" value="1" />
    <column name="dDATA" calculated="0" formula="" value="5" />
    <column name="Total_DS" calculated="1" formula="cDATA+dDATA" value="6" />
  </columns>
  <columns day="Friday" date="12/2/2011 12:00:00 AM">
    <column name="cDATA" calculated="0" formula="" value="2" />
    <column name="dDATA" calculated="0" formula="" value="4" />
    <column name="Total_DS" calculated="1" formula="cDATA+dDATA" value="6" />
  </columns> </reportdata>


I am trying to fill dataset from above xml and assign dataset to datagridview
C#
BLL.Dailydrawer oBO = new BLL.Dailydrawer();
             DataTable   DTPrevMonth = oBO.FillPreviousMonths();
 DataRow[] DR = DTPrevMonth.Select(string.Format("MonthId = {0}", PrevMonthId));
                string XML = Convert.ToString(DR[0]["DataXML"]);
               
                DataSet DS = new DataSet();
                System.IO.StringReader xmlSR = new System.IO.StringReader(XML);

                DS.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);


but dataset display nothing.
Please help me urgent how can i do this?
Posted
Updated 22-Dec-11 19:09pm
v3

DS.ReadXml(mappath("file.xml"));
 
Share this answer
 
v2
Comments
RaviRanjanKr 23-Dec-11 1:37am    
[Edited]Code is wrapped in pre tag[/Edited]
Assuming you are working in winforms,
DataSet ds = new DataSet();
            ds.ReadXml(Application.StartupPath.Replace("\\bin\\Debug","")+"\\XMLFile1.xml");


this will load the xml file in dataset, if the xml file is in the root folder..
 
Share this answer
 
v2
Comments
RaviRanjanKr 23-Dec-11 1:36am    
[Edited]Code is wrapped in pre tag[/Edited]
Try
DataSet ds = new DataSet();
    ds.ReadXml(@"YourXML FIle");

or
Reference Link :- Fill DataSet with the data from XML[^]
XmlDataDocument xmlDatadoc = new XmlDataDocument();
   xmlDatadoc.DataSet.ReadXml("Your XML File");

   DataSet ds = new DataSet("DatSet Name");
   ds = xmlDatadoc.DataSet;

Reference Link :- Load XML to DataSet[^]
 
Share this answer
 
Please use below code

string myXMLfile = "C:\\MySchema.xml";
  DataSet ds = new DataSet();
  try
  {
      ds.ReadXml(myXMLfile);
      dataGrid1.DataSource = ds;
      dataGrid1.DataMember = "Cust";
  }
  catch (Exception ex)
  {
      MessageBox.Show(ex.ToString());
  }


Please let me know if it is work for you
 
Share this answer
 
Comments
sagar15modi 23-Dec-11 0:40am    
i am trying to fill dataset from xml string not xml file
and i want to convert above xml to datset / datatable

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900