Solved

C# Datatable  - how to extract a specific value

Posted on 2014-03-27
3
234 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 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