CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    How do I access specific values from a DataSet?

    I have need to access specific data values from an ASP.NET DataSet. In my case, I am using an XML file as the data source. When the page loads, I have no problem loading the XML data into a DataGrid to display on the page (there are many examples of this on the Internet).
    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet oDS = new DataSet();
            oDS.ReadXml(Request.PhysicalApplicationPath + "BenchMarks.xml");
            GridView1.DataSource = oDS;
            GridView1.DataBind();
    
        }
    Now that the data has been loaded, I need to access specific values directly from it, and load them into floats. I believe that this might be accomplished using SqlDataAdapter, but I cannot figure out how to do this.
    For example, it might be something like,
    Code:
    SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROm  Categories",myConnection);
    but I am uncertain what the table name would be, nor was it necessary to build a connection string to access the XML data file.
    Here is a portion of my data file to show the problem of identifying a table name:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <BENCHMARKS>
      <ROW>
        <PROC>CABG</PROC>
        <DEATH> 2.3</DEATH>
        <STROKE>1.1</STROKE>
        <RENAL>3.5</RENAL>
        <RESP>9.2</RESP>
        <WOUND>0.3</WOUND>
        <REOP>5.0</REOP>
        <ANY>14.8</ANY>
        <STAY14D>5.6</STAY14D>
        <STAY6D>50.0</STAY6D>
      </ROW>
      <ROW>
        <PROC>AVREPL</PROC>
        <DEATH> 2.3</DEATH>
        <STROKE>1.1</STROKE>
        <RENAL>3.5</RENAL>
        <RESP>9.2</RESP>
        <WOUND>0.3</WOUND>
        <REOP>5.0</REOP>
        <ANY>14.8</ANY>
        <STAY14D>5.6</STAY14D>
        <STAY6D>50.0</STAY6D>
      </ROW>    
    </BENCHMARKS>
    In other words, I need to be able to execute an SQL statement like
    SELECT DEATH FROM BENCHMARKS WHERE PROC = 'CABG'
    How to make this work? Or is there a better way?
    mpliam

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: How do I access specific values from a DataSet?

    You shouldn't use a SqlDataAdapter for reading XML files - it's used to in connection with a database datasource.

    There are a number of ways to do what you ask - the easiest is to properly simply open the XML document using an XML Reader and then read through your file and get the node values you want from that reader.

  3. #3
    Join Date
    Jun 2010
    Location
    Cairo, Egypt
    Posts
    17

    Re: How do I access specific values from a DataSet?

    hay,
    you need to use LINQ
    it will get you the row through the XML file

  4. #4
    Join Date
    May 2002
    Posts
    1,798

    Re: How do I access specific values from a DataSet?

    I'll give Linq a try. Thanks.
    mpliam

  5. #5
    Join Date
    Jun 2010
    Location
    Cairo, Egypt
    Posts
    17

    Re: How do I access specific values from a DataSet?


  6. #6
    Join Date
    May 2002
    Posts
    1,798

    Re: How do I access specific values from a DataSet?

    Good link for linq beginner. Thanks.
    mpliam

  7. #7
    Join Date
    Jun 2010
    Location
    Cairo, Egypt
    Posts
    17

    Re: How do I access specific values from a DataSet?

    you are welcome
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    010011000111010101110110001000000100110101111001001000000101000001100011

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured