Solved

C# Datatable  - how to extract a specific value

Posted on 2014-03-27
3
229 Views
Last Modified: 2014-03-27
Hi All

I have a C# datatable populated by a SQL statment.

Say the datatable has returned a 100 records and there are five coloumn headers, how do I just display record 50, coloumn 2 from the datatable

I'd guess something like Console.Write(MyDatatable.rows[50].Coloumns[2])

but it's just not happening
0
Comment
Question by:MrDavidThorn
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39959211
You can access a row's ItemArray
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 39959224
like
MyDatatable.Rows[50].ItemArray[2]
0
 
LVL 9

Expert Comment

by:dustock
ID: 39959237
Its going to be base 0 so you'll want this.

MyDataTable.Rows[49].ItemArray[1].ToString();

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now