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
Quote:
SELECT DEATH FROM BENCHMARKS WHERE PROC = 'CABG'
How to make this work? Or is there a better way? :confused:
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.
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
Re: How do I access specific values from a DataSet?
I'll give Linq a try. Thanks. :)
Re: How do I access specific values from a DataSet?
Re: How do I access specific values from a DataSet?
Good link for linq beginner. Thanks. :)
Re: How do I access specific values from a DataSet?