473,387 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Querying in DataTable

Hi,

I have a DataTable with three columns (2 int, and 1 string). Now I
would like a query that return the total number of different integers
in one of the interger columns.

For example
Name Age Class
A 12 4
B 13 5
C 11 3
D 12 3
Now if I select the total number of different integers in the Age
column the answer is 3(because 11, 12 ,13).

Is this possible to do?
Can someone help me out
Thanks in Advance

Nov 17 '05 #1
6 1601
sql query or in program?

sql query is like:

SELECT COUNT(DISTINCT(age))
FROM Table
if you want to do that in program, i dont think there is such a function in
DataTable class. so you can try looping through all rows manually and find
by yourself
Nov 17 '05 #2
I'm to use it from a DataTable. Is that sort of query available in
someway using xml?, because the data is also available in an xml file.

Nov 17 '05 #3
Using the following code I succeded to count the number of rows, but
not required result.
XmlTextReader reader = new
XmlTextReader(File.OpenText("c:\\test.xml"));
XPathDocument doc = new XPathDocument(reader, XmlSpace.Preserve);
XPathNavigator nav = doc.CreateNavigator();

XPathExpression exp = nav.Compile("count(//Persons/Person/Age)");

Console.WriteLine(nav.Evaluate(exp).ToString());

This return 4, not 3. What further modifications can be done?

Nov 17 '05 #4
i think yes. but i dont remember how. a xpath query will probably will be
able to do that.
Nov 17 '05 #5
If found this code on the net, but the following Result is being
returned: 'System.Xml.XPath.XPathSelectionIterator'.

What should my problem be?

XmlTextReader reader = new
XmlTextReader(File.OpenText("c:\\test.xml"));
XPathDocument doc = new XPathDocument(reader, XmlSpace.Preserve);
XPathNavigator nav = doc.CreateNavigator();

XPathExpression exp =
nav.Compile("//Statistics/ProcessState[not(ProcessID =
preceding-sibling::ProcessState/ProcessID)]/ProcessID");

Console.WriteLine(nav.Evaluate(exp));

Nov 17 '05 #6
Hi Curious!

Try this:
SELECT COUNT(DISTINCT Age) AS AgeCount FROM Table1

Wolfgang
"Curious" <th****@mail.global.net.mt> schrieb im Newsbeitrag
news:11********************@g44g2000cwa.googlegrou ps.com...
Hi,

I have a DataTable with three columns (2 int, and 1 string). Now I
would like a query that return the total number of different integers
in one of the interger columns.

For example
Name Age Class
A 12 4
B 13 5
C 11 3
D 12 3
Now if I select the total number of different integers in the Age
column the answer is 3(because 11, 12 ,13).

Is this possible to do?
Can someone help me out
Thanks in Advance

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Dan Koster | last post by:
I have three weeks of history for all user accounts stored in a DataSet (dsAccountsHistory). I want to be able to narrow that data down to one specific user, at runtime, without having to make...
2
by: Elliot Rodriguez | last post by:
As I continue to read more about the benefits of database querying using ADO.NET, I am having a more difficult time distinguishing what the best approach to data retrieval is anymore. When...
6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
3
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
8
by: JC | last post by:
I have created a data adapter (CheckVacationHrsDataAdapter1) and generated a dataset (CheckHrsVacDataSet1) in the form designer. What I would like to do is query this dataset, find the sum of...
4
by: onecorp | last post by:
I have a SQL table comprised of 31 columns. The first column is simply an id column, the next 30 columns are labelled ,.... The numerical columns have a tinyint type and the data stored is either...
0
by: ranganadh | last post by:
Dear Group members, I am new to LINQ, pls help on the deeling with huge amount of data with the C# stand Alone application. I have two file, which contains more then 2 lacs lines in every...
1
by: mcfly1204 | last post by:
As it stands now, I have a tab delimited source file with data to be used by my app. Currently, I am reading the file into a datatable, but I need to group the rows of the datatable and use that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.