|
-
June 13th, 2010, 03:44 PM
#1
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
-
June 14th, 2010, 01:49 AM
#2
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.
-
June 25th, 2010, 06:41 PM
#3
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
-
June 25th, 2010, 08:33 PM
#4
Re: How do I access specific values from a DataSet?
I'll give Linq a try. Thanks.
mpliam
-
June 26th, 2010, 08:02 AM
#5
Re: How do I access specific values from a DataSet?
-
June 26th, 2010, 03:08 PM
#6
Re: How do I access specific values from a DataSet?
Good link for linq beginner. Thanks.
mpliam
-
June 26th, 2010, 05:14 PM
#7
Re: How do I access specific values from a DataSet?
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|