C# .NET - create multiple xml files from one dataset using c#
Asked By samaira samaira
03-Feb-12 05:27 AM
I need to create multiple xml files from one dataset.
I have a dataset with many records, each has it's own ID number. I need to
create an xml file for each ID. Can I loop through the datatable, by datarow,
and write that row to an xml file? any code samples.....
kalpana aparnathi replied to samaira samaira
hi,
Here give you one importance pdf file for your solution . hope will help you please http://www.scsug.org/SCSUGProceedings/2008/papers/app/Mayumi_Takada.pdf
Thanks,
dipa ahuja replied to samaira samaira
You have to use the session for this because the row count becomes 0 when you execute the code:
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
dt.TableName = "t1";
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Age", typeof(string));
}
protected void Button3_Click(object sender, EventArgs e)
{
if (Session["dt"] != null)
{
dt = (DataTable)Session["dt"];
}
dt.Rows.Add(txt1.Text, txt2.Text);
Session["dt"] = dt;
dt.WriteXml(@"C:\SS.XML");
}
Same way u can add more table in dataSet and create the XML file
Somesh Yadav replied to samaira samaira
you can try this
string filename = Address.Text;
dataGridView1.AutoGenerateColumns = true;
DataSet dataSet1 = new DataSet("DEFAULT");
dataSet1.ReadXml(filename, XmlReadMode.Auto);
bindingSource1.DataSource = dataSet1.Tables[(int)tablenumber.value].DefaultView;
dataGridView1.DataSource = bindingSource1;
richTextBox1.Text = filename + " loaded.";
label2.Text = "File Open: " + filename;

object sender, GridViewRowEventArgs e) { if (e.Row.RowType = = DataControlRowType.DataRow) { e.Row.Attributes. Add ( "onclick" , Page.ClientScript.GetPostBackEventReference(sender as GridView, "Select$" + e.Row.RowIndex.ToString())); } } What the above code does because ASP.NET uses the $ as its control hierachy delimiter. What will result in the page is something like this, where the 'Select$2' represents the second row of the Grid other bindable object) the user selected. The rest is simple: protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow row = this .GridView1.SelectedRow; DataTable dt = (DataTable) Cache[ "dt" ]; int y = row.DataItemIndex tricks to make all this work properly: 1. You must have EnableEventValidation = "false" in your @Page declaration. Otherwise, the runtime will attempt to validate the generated event items and it will new DataSet(); XmlReader rdr = XmlReader. Create ( "http: / / www.eggheadcafe.com / rss.xml" ); ds.ReadXml(rdr, XmlReadMode.InferSchema); if (Cache[ "dt" ] = = null ) Cache[ "dt" ] = ds.Tables[2]; GridView1.DataSource = (DataTable)Cache[ "dt it up! You can download the Solution here and see all the details in the page and it's codebehind. Popularity ( 10116 Views ) View Peter Bromberg's Articles Picture Biography - Peter
asynchronous postback and the next is when the call ends. protected void btnSubmit_OnClick( object sender, EventArgs e) { if (Page.IsValid) { System.Threading.Thread.Sleep(1200); DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath( "~ / db / Contacts.xml" ), XmlReadMode.InferSchema); DataRow drow = ds.Tables[ "contact" ].NewRow(); drow[ "name" ] = txtName.Text; drow[ "age" ] = txtAge.Text head> <title> < / title> <script type = "text / javascript" > var url = ' http: / / www.google.com ' ; / / the details page you want to display. . . < / script> <style> .loading-indicator { font-size:8pt; background-image:url(. . / images color:#003366; width:180px; text-align:center; } < / style> <div id = "loading" > <div class = "loading-indicator" > Page Loading. . . < / div> < / div> < / head> <body onload = "location.href = url;" style = "overflow:hidden;overflow-y:hidden
Imports System.Text Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim symbol As [String] = txtQuotes.Text Dim request As HttpWebRequest Dim response Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim s As String() = txtOutput1.Text.Split(", ") Dim word As String 'Dim new DataSet(); ms.Seek(0, 0); / / rewind it, just in case. . . try { ds.ReadXml(ms, XmlReadMode.InferSchema); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message+ex.StackTrace); } return ds; } / / end get realtime quotes from Yahoo finance, and read out the string of Yahoo's web page from the stream. Then I just use old fashioned substring searching and positioning to scrape UTF-8 byte order mark characters in your stream: private void button1_Click( object sender, System.EventArgs e) { YahooMultiQuote.Service1 s = new YahooMultiQuote.Service1(); s.RequestEncoding = new System.Text.ASCIIEncoding(); DataSet ds com / finance / company.html other finance web services http: / / www.soatrader.com / web-services / finance / Page-8.html Just right click on your site -> Add web service reference -> add the url textbox and Sign In button) source html code via viewing source(Right-click on web page -> "View Source" menu item). The following code sample can login in Yahoo successfully. Please take Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Part 1: Load Yahoo login page in Form_Load event WebBrowser1.Navigate(" https
list controls. • Bind the GridView and DataList controls to XML data. • Create a master-detail page that displays logically related XML data. • Apply a transformation to an .xml file to make you can read an external XML file and update the data content of your web page. XML Simplifies Data Sharing In the real world, computer systems and databases contain data in sources. The synatx for the ReadXml method is as follows: ReadXml (Stream | FileName | textReader | XmlReader , XmlReadMode ) The XmlReadMode parameter can take any of the values listed in the following table: VALUES DESCIPTION Auto If the DataSet already has schema or the document contains an inline schema, it sets XmlReadMode to ReadSchema. 2. If the DataSet does not already have a schema and the document does not contain an inline schema, it sets XmlReadMode to InferSchema. DiffGram Reads a Diffgram, which is a format that contains both the original to the DataGrid control by adding the following code to the Load event of the page in the .aspx page. private void Page_Load( object sender, System.EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml (MapPath
RSS feed and make a nice display out of it in an ASP.NET Web page. After a little thought, I realized that our good friends, the DataSet and the DataGrid The basic code to do this is as follows: private void Page_Load(object sender, System.EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml("http: / / www.eggheadcafe.com / rss.xml", XmlReadMode.Auto); DataGrid1.DataSource = ds.Tables[2]; DataGrid1.DataBind(); } Is that simple enough? I would hope so! Your in-page DataGrid HTML Code after setting some nice properties in the Designer, might look like this CurrentPageIndex = e.NewPageIndex; DataSet ds = new DataSet(); ds.ReadXml("http: / / www.eggheadcafe.com / rss.xml", XmlReadMode.Auto); DataGrid1.DataSource = ds.Tables[2]; DataGrid1.DataBind(); } Finally, if you are behind a firewall