简体   繁体   中英

Get list of row from a DataSet

I have this dataset like this:

在此处输入图片说明

How can I get the string "TITLE" and "SUMMARY"?

I have this code:

string path = @"C:\Users\Pichau\Downloads\teste\data.xml";
XmlDocument x = new XmlDocument();
x.Load(path);
StringReader stream = new StringReader(x.InnerXml);
DataSet ds = new DataSet();
ds.ReadXml(stream);

foreach (var i in ds.Tables["col"].Columns)
{
    Console.WriteLine(i.ToString());
}

Console.ReadLine();

But with this code I get the following output:

name
type
col_Text
row_Id

I want to access the value of "TITLE" in the "name" column

You will need to find the DataRow that corresponds to your TITLE and SUMMARY rows, and then access the values of the appropriate columns.

Try this:

foreach (DataRow row in ds.Tables["col"].Rows) {
   if (row["name"] == "TITLE") {
      Console.WriteLine(row["col_Text"]);
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM