Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
foreach (DataTable table in ds.Tables)  
{
   XmlElement element = xmlDoc.CreateElement("data");
   strJson = json.json_string(ds.Tables[0]);
   strjson1 = json.json_string(ds.Tables[1]);
   strJson3 = json.json_string(ds.Tables[2]);
   strjson4 = json.json_string(ds.Tables[3])
}

in my dataset i have 4 tables i am converted 4 strings now how can i assign these string into xml elements .. using foreach loop .why i'm choosing is suppose if 4 xml elements created manually but in future n elements so how to assign these strings into xml elements
Posted
Updated 26-May-14 8:52am
v3
Comments
anup.bhunia 26-May-14 14:52pm    
Could you please elaborate little bit to explain what output you exactly expecting?
Sergey Alexandrovich Kryukov 26-May-14 14:53pm    
Not clear... XMK, JSON... they are unrelated. What are you trying to achieve?
—SA
gggustafson 26-May-14 17:07pm    
Have you explored DataTable.WriteXML?
srikanth492 27-May-14 5:35am    
iam doing like this but int that code every table i create one element .....so using looping concept automatically created...that code i want can u tell me example of that code........
string strJson = string.Empty; //string
string strjson1 = string.Empty;
stringjson json = new stringjson(); //converted datatable to string
properties_employeepayment emppayments = new properties_employeepayment();

abs_DAL_payhistory history = new abs_DAL_payhistory();
DataSet ds = history.paymenthistory(emppayments);
DataTable dt = ds.Tables[0];
DataTable dt1 = ds.Tables[1];

if (dt.Rows.Count > 0)
{
strJson = json.json_string(dt);
}

if (dt1.Rows.Count > 0)
{
strjson1 = json.json_string(dt1);
}
XmlDocument xmlDoc = new XmlDocument(); //iam creating 3 xml elements and added that strings
XmlElement element = xmlDoc.CreateElement("data");
XmlElement Paiddata = xmlDoc.CreateElement("getpaiddata");
XmlElement Unpaiddata = xmlDoc.CreateElement("getunpaiddata");
Paiddata.InnerText = strJson;
Unpaiddata.InnerText = strjson1;
element.AppendChild(Paiddata);
element.AppendChild(Unpaiddata);
xmlDoc.AppendChild(element);

StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xmlDoc.WriteTo(xw);
gggustafson 27-May-14 14:40pm    
Are you addressing this question to me? If so in the furure you need to click on the reply button for the person you want to address. I do not get any email notifications if you dont. Click on reply to this message to answer.

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