C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » XML »

Populate a Dataset with an XML file


Posted Date: 24 Feb 2009    Resource Type: Code Snippets    Category: XML
Author: Rajib BanerjeeMember Level: Silver    
Rating: 1 out of 5Points: 10



'Get the relevant XML file and populate a DataSet

Private Sub GetDataSet(ByRef ds As DataSet, ByVal filename As String)
ds = New DataSet
Dim xmlMenuDoc As XmlDocument = New XmlDocument()

xmlMenuDoc.Load("AddrTest.xml")
Dim xmlString As StringReader = New StringReader(xmlMenuDoc.InnerXml)
ds.ReadXml(xmlString)
End Sub


Attachments

  • ADDRESS TEST (26361-241522-AddrTest.xml)



  • Responses

    Author: Sree Harsha    27 Apr 2009Member Level: Bronze   Points : 2
    I have written code for filling dataset with xml document and associate the same to gridview.

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    binddata();
    }
    }
    void binddata()
    {
    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath(”empdata.xml”));
    gv.DataSource = ds;
    gv.DataBind();
    }
    protected void Editdata(object s, GridViewEditEventArgs e)
    {
    gv.EditIndex = e.NewEditIndex;
    binddata();
    }
    protected void Deletedata(object s, GridViewDeleteEventArgs e)
    {
    binddata();
    DataSet ds= gv.DataSource as DataSet;
    ds.Tables[0].Rows[gv.Rows[e.RowIndex].DataItemIndex].Delete();
    ds.WriteXml(Server.MapPath(”empdata.xml”));
    binddata ();
    }
    protected void Canceldata(object s, GridViewCancelEditEventArgs e)
    {
    gv.EditIndex = -1;
    binddata();
    }
    protected void Updatedata(object s, GridViewUpdateEventArgs e)
    {
    int i = e.RowIndex;
    string id=(gv.Rows[e.RowIndex].FindControl(”txtid”) as TextBox).Text;
    string name=(gv.Rows[e.RowIndex].FindControl(”txtname”) as TextBox).Text;
    string city=(gv.Rows[e.RowIndex].FindControl(”txtcity”) as TextBox).Text;
    string salary=(gv.Rows[e.RowIndex].FindControl(”txtsalary”) as TextBox).Text;
    gv.EditIndex = -1;
    binddata();
    DataSet ds =(DataSet) gv.DataSource;
    ds.Tables[0].Rows[i]["empid"] = id;
    ds.Tables[0].Rows[i]["empname"] = name;
    ds.Tables[0].Rows[i]["empcity"] = city;
    ds.Tables[0].Rows[i]["empsalary"] = salary;
    ds.WriteXml(Server.MapPath(”empdata.xml”));
    binddata();
    }
    protected void pageddata(object s, GridViewPageEventArgs e)
    {
    gv.PageIndex = e.NewPageIndex;
    binddata();
    }
    protected void insert(object sender, EventArgs e)
    {
    binddata();
    DataSet ds = gv.DataSource as DataSet;
    DataRow dr = ds.Tables[0].NewRow();
    dr[0] = empId.Text;
    dr[1] = empName.Text;
    dr[2] = empcity.Text;
    dr[3] = empsalary.Text;
    ds.Tables[0].Rows.Add(dr);
    ds.AcceptChanges();
    ds.WriteXml(Server.MapPath(”empdata.xml”));
    binddata();
    empId.Text = string.Empty;
    empcity.Text = string.Empty;
    empName.Text = string.Empty;
    empsalary.Text = string.Empty;
    }



    Author: Kirankumar Potnuru    15 May 2009Member Level: Gold   Points : 1
    Do you have any idea for data binding for data grid at device aplication (compact framework 2.0 or greater versions) and data is coming from xml not from data base......!!!!


    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    XML  .  ASP.NET  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Embedding binary data in XML
    Previous Resource: Database values into to XML file
    Return to Discussion Resource Index
    Post New Resource
    Category: XML


    Post resources and earn money!
     
    Related Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use