Answered by:
Accessing specific columns of a datatable

Question
-
I want to use specific cells of each row of a datatable.
I tried following in C# :
DataTable.Rows[Index].Column[Index]
- Edited by Aarsh (MCTS) Tuesday, January 17, 2012 7:57 AM
Tuesday, January 17, 2012 7:51 AM
Answers
-
The Syntax is,
DataTable.Rows[Index].[Index]
For prompt response of any Ado.net specific question please use
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads.
Lingaraj Mishra- Proposed as answer by CK Shinde Tuesday, January 17, 2012 1:46 PM
- Marked as answer by Yi-Lun Luo Monday, January 23, 2012 8:33 AM
Tuesday, January 17, 2012 12:39 PM -
When you say "Failed" what do you mean? If you got an IndexOutOfRangeException then it's likely b/c there aren't any rows or you're looking past the # of rows/columns. You can just use a simplified syntax though - DataTableName.Rows[RowIndex][ColumnIndex]. You'll likely want to cast the value to whatever type you're expecting, and you'll want to check for Null just to be completely safe but that should do it for you unless I'm misunderstanding the question.
Cordially, W.G.Ryan - www.williamgryan.mobi- Marked as answer by Yi-Lun Luo Monday, January 23, 2012 8:33 AM
Tuesday, January 17, 2012 9:27 PM
All replies
-
Hello, it is recommended to use Entity Framework to work with database. DataSet should only be used for backward compatibility. In addition, your question has nothing to do with WCF. If you have to use DataSet, please post the question on http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.- Proposed as answer by Anup Hosur Wednesday, January 18, 2012 10:18 AM
Tuesday, January 17, 2012 11:59 AM -
The Syntax is,
DataTable.Rows[Index].[Index]
For prompt response of any Ado.net specific question please use
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads.
Lingaraj Mishra- Proposed as answer by CK Shinde Tuesday, January 17, 2012 1:46 PM
- Marked as answer by Yi-Lun Luo Monday, January 23, 2012 8:33 AM
Tuesday, January 17, 2012 12:39 PM -
When you say "Failed" what do you mean? If you got an IndexOutOfRangeException then it's likely b/c there aren't any rows or you're looking past the # of rows/columns. You can just use a simplified syntax though - DataTableName.Rows[RowIndex][ColumnIndex]. You'll likely want to cast the value to whatever type you're expecting, and you'll want to check for Null just to be completely safe but that should do it for you unless I'm misunderstanding the question.
Cordially, W.G.Ryan - www.williamgryan.mobi- Marked as answer by Yi-Lun Luo Monday, January 23, 2012 8:33 AM
Tuesday, January 17, 2012 9:27 PM