简体   繁体   中英

Get specific row of datatable

I have a big datatable like this:

在此处输入图片说明

Query for this list is:

var currentDesignKey = (from DataRow dr in designFolioList.Rows select (int)dr["DesignKey"]).FirstOrDefault()

As you can see I have a FirstOrDefault() which always get DataRow [0] of table, I want to know how can I get specific table something like:

(from DataRow dr in designFolioList.Rows select (int)dr["DesignKey"])[11]

How can I achieve that? Regards

You can access a specific DataRow in the Rows collection directly by indexer.

var key = (int)designFolioList.Rows[11]["DesignKey"];

will retrieve the 12th row's DesignKey column value and cast it to an Int32.

You would do well to actually check that there are enough rows in the table before trying direct index access, otherwise you may get an IndexOutOfRangeException .

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