Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a data in my datatable which i want in xml format.I have no idea where to start with.Any help is appreaciated.Below is the code where i get the data from my datatable.Please help me out with some good links or suggestions.


string querystring = Request.QueryString["Userid"];


DataTable dtfrnameid = new DataTable();
connfordata.Open();
SqlCommand cmdfrnameid = new SqlCommand("select s000_UserId from s000_users where (s000_firstname+s000_lastname) = '" + querystring + "'", connfordata);
SqlDataAdapter dafrnameid = new SqlDataAdapter(cmdfrnameid);
dafrnameid.Fill(dtfrnameid);
connfordata.Close();

string id = dtfrnameid.Rows[0][0].ToString();



lblfrogridview.Text = "";
string weekending = gvweeklysum.Rows[rindex].Cells[1].Text;
DateTime getweekending = Convert.ToDateTime(weekending);
DateTime dtmonday = getweekending.AddDays(-4);
DateTime castdttime = dtmonday.AddHours(12);
var monday = castdttime.Date.ToString("yyyy-MM-dd 12:mm:ss");

DataTable dtfrmonday = new DataTable();
connfordata.Open();
SqlCommand cmdfrmonday = new SqlCommand("SRTSWeeklySummaryWednesday", connfordata);
SqlDataAdapter dafrmonday = new SqlDataAdapter(cmdfrmonday);
cmdfrmonday.CommandType = CommandType.StoredProcedure;
cmdfrmonday.Parameters.Add(new SqlParameter("@createddate", SqlDbType.DateTime)).Value = monday;
cmdfrmonday.Parameters.Add(new SqlParameter("@userid", SqlDbType.Int)).Value = id;

dafrmonday.Fill(dtfrmonday);
connfordata.Close();
Posted
Comments
berrymaria 29-Jul-13 20:20pm    
Do you mean Reading XML Data into a DataTable?
Amit Karyekar 29-Jul-13 20:24pm    
I mean getting my datatable data into xml for example my datatable is having having col. name and age having a row (mango,1).So it should give result.
name mango /name
age 1 /age
berrymaria 29-Jul-13 21:34pm    
Ahh, okay. I didn't get any notifications. You didn't reply on my comment. See my answer below. It might help you. :)

try WriteXml Method

C#
/*Export datatable to xml */
dtfrmonday.TableName = "MyTable";
dtfrmonday.WriteXml("Path\FileName.xml", XmlWriteMode.WriteSchema);

/*Import xml to datatable */
dtfrmonday.TableName = "MyTable";
dtfrmonday.ReadXml("Path\FileName.xml");
 
Share this answer
 
I suggest you take a look at the XML classes. You will need to do most of it yourself but once you have the data it is just a matter of writing the XML file.

Click Here[^] for a good simple tutorial on creating an XML once you have the data.
 
Share this answer
 
See this link:

DataTable.WriteXml Method[^]

Hope it helps! :)
 
Share this 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