473,405 Members | 2,338 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,405 software developers and data experts.

question about query datatable

Hi,

I would like to query a datatable in C#. The query is like

select sum(quantity)
from table
where company="IBM"

And I would get this number and display it in my GUI.
Is there a way to do it?
Thanks

Chrisben
Nov 16 '05 #1
3 15913
To further clarify my question, the datatable is a datatable object I created
in C#. It is the datasource for my DataGrid. I do NOT need to query sql
server database, instead, I need to do the same thing on the table created in
the C#. thanks

"chrisben" wrote:
Hi,

I would like to query a datatable in C#. The query is like

select sum(quantity)
from table
where company="IBM"

And I would get this number and display it in my GUI.
Is there a way to do it?
Thanks

Chrisben

Nov 16 '05 #2
You use the DataTable.Select method or DataTable.Compute method
to perform queries against a DataTable.

Decimal val = dt.Compute("Sum(quantity)","company='IBM'");

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"chrisben" <ch******@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi,

I would like to query a datatable in C#. The query is like

select sum(quantity)
from table
where company="IBM"

And I would get this number and display it in my GUI.
Is there a way to do it?
Thanks

Chrisben

Nov 16 '05 #3
this is exactly what I am looking for. Thanks a lot

Chris

"Robbe Morris [C# MVP]" wrote:
You use the DataTable.Select method or DataTable.Compute method
to perform queries against a DataTable.

Decimal val = dt.Compute("Sum(quantity)","company='IBM'");

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"chrisben" <ch******@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Hi,

I would like to query a datatable in C#. The query is like

select sum(quantity)
from table
where company="IBM"

And I would get this number and display it in my GUI.
Is there a way to do it?
Thanks

Chrisben


Nov 16 '05 #4

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

Similar topics

1
by: Nick | last post by:
I am working on a application that uses the MyApplication_UnhandledException event to basically tell the user that I screwed up somewhere...see below Private Sub...
1
by: garyusenet | last post by:
I'm using MS VB Express Ed. 2005. I have an sql database. This database has one table, and there is a column called salesman. I want to AUTOMATICALLY enter the salesman name for every new...
2
by: | last post by:
Hello all I have a dataset which contains 3 datatables. I traverse each datatable and check the rows. I should be able to get values out of these datatables and create a new datatable? Is this...
3
by: Peter | last post by:
Hi, I have two datatables and I want to efficiently query the intersection of the two using the studentID. In my example code below, I want to print out Mary and Jane and their exam grades and I...
1
by: cindy | last post by:
Get data into datatable, add to dataset dsSearch " Get data into datatable, add to dataset dsSearch Using In-Memory SQL Engine join the tables and select the filenames from the join, add to...
5
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored...
10
by: Nemisis | last post by:
HI everyone, I think i am on the right path but if someone could confirm it, that would be great. In my business Layer i have my business object, for this example, called User. User has...
5
by: Stan SR | last post by:
Hi, Some newbie questions.. :-) First, what is the namespace to use for the Cache class ? When I use this bit of code I get an error if (Cache==null) Cache.Insert("myUserList",userlist);...
3
by: Oenone | last post by:
I have a project that creates a SqlDataAdapter and uses its Fill method to fill a DataTable with data from a user-provided query. From there I can obviously access details about the rows and...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.