reading from XML database

Last post 05-12-2008 6:08 AM by Samu Zhang - MSFT. 3 replies.

Sort Posts:

  • reading from XML database

    05-06-2008, 2:11 PM
    hello.. i have a database as follows: DEC Coding thakjdskcjksl sdjhckjds sdjhcfjkef 3 DJ hsdhc@jshsdcj alice jdhcj@ bhakti hdfcjhsjdf Debu shdcjhs@jmndfv jfgjd Discussion bbhdgbdfbd 2 dfbfdcgb bdfbd@kjfkvs dg bdfg hh dfbfghnb ghj@dtghh i want a query to retrive and and depending on the value of If the value of is suppose "Discussion".. then i want to retrive only those values of that and want to display in the dataGridView.. please help me with the code... thanks..
  • Re: reading from XML database

    05-07-2008, 6:27 AM

    Hi bhakti ,

    I basically understand your question.

    I wrote one sample, I will use xpath to pick out nodes which person's gender equals man.

     

    <root>
      <person>
        <name>aaa</name>
        <gender>man</gender>
      </person>
      <person>
        <name>bbb</name>
        <gender>man</gender>
      </person>
      <person>
        <name>bbb</name>
        <gender>woman</gender>
      </person>
    </root>
      
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("XMLFile32.xml"));
            XmlNodeList lst = doc.SelectNodes("//person[gender='man']");
            ArrayList arrlst = new ArrayList();
            for (int i = 0; i < lst.Count; i++)
            {
                Person p = new Person ();
                p.Name = lst[i].SelectSingleNode("name").InnerText;
                p.Gender = lst[i].SelectSingleNode("gender").InnerText;
                arrlst.Add(p);
    
            }
            this.GridView1.DataSource = arrlst;
            GridView1.DataBind();
        }
      
    class Person
    {
        string name;
    
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string gender;
    
        public string Gender
        {
            get { return gender; }
            set { gender = value; }
        }
    
    }

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: reading from XML database

    05-09-2008, 1:15 AM

    hello Sir, 

    thanks for the reply... 

    I m workin in C#.NET, i cant find any gridView in that. ther is datagridView but has no dataBind() property in it.

    so can u help wit the code.... 

    My XML document is as follows: 

     
    <discussion>
      <project>
        <id>112</id>
        <pname>Desktop Email client</pname>
        <stage>Discussion</stage>
        <description>good project</description>
        <no_mem>3</no_mem>
        <lname>Daljeet</lname>
        <lmail_id>dj@honey4u.com</lmail_id>
        <mname>debu</mname>
        <mmail_id>d@y.com</mmail_id>
        <mname>alice</mname>
        <mmail_id>a@y.com</mmail_id>
        <mname>bhakti</mname>
        <mmail_id>b@y.com</mmail_id>
      </project>
      <project>
        <id>113</id>
        <pname>IRIS scan</pname>
        <stage>Discussion</stage>
        <description>hi5 project</description>
        <no_mem>1</no_mem>
        <lname>Amit</lname>
        <lmail_id>jfhj</lmail_id>
        <mname>Atul</mname>
        <mmail_id>sjdcnjsd</mmail_id>
      </project>
    </discussion>
     
     

      Now from here i want all "mname" and "mmail_id" of the node "project" where id=112

    how do i write a query in C#.NET and display in "DATAGRIDVIEW of C#.NET???

    PLEASE help me wit the code...

    Thank you... 

  • Re: reading from XML database

    05-12-2008, 6:08 AM
    Answer

    Hi bhakti.bhatale ,

    You can retrieve that project node first which id equals 112 , then get mname and mmail_id nodes.

     

            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("XMLFile34.xml"));
            XmlNode pro = doc.SelectSingleNode("//project[id = '112']");
            XmlNodeList mname = pro.SelectNodes("mname");
            XmlNodeList mmail_id = pro.SelectNodes("mmail_id");
    bhakti.bhatale:
    how do i write a query in C#.NET and display in "DATAGRIDVIEW of C#.NET???

    DataGridView is one WinForm control , GridView is one WebForm control. So you can post your answer here :

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=7&SiteID=1

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (4 items)