Solved

C#, SQL database Evaluate data

Posted on 2013-10-25
2
311 Views
Last Modified: 2013-10-28
Good morning experts, I have a current project I need to evaluate some data from a SQL database, I'll use C# to connect to it, but I'm not sure how I would evaluate the data as I'm retrieving it....

Just as a simple for instance:

Suppose I have a database with 3 columns, Firstname, lastname, title - in C# if I wanted to go through each record and if "Title" == "Manager" then increment my count of managers +1 (mgrCount++)....  (This is just a quick example, but if I can evaluate this even, then i would be able to figure out what I was doing)

Thank you again.

I would assume I need to do something to my datareader in my while loop as I'm looping though the information, correct?

while(rdr.Read())
{
if(rdr.[0].ToString() == "Manager"
{
mgrCount++;
}


}

Would something like this work?

Thank you.
0
Comment
Question by:hej613
  • 2
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39600255
Yes but:

SELECT Count(1) AS Expr1
FROM [YourTableNameGoesHere]
GROUP BY [Title]
HAVING (Title='Manager');

this should return one record, the total number of records where the title is Manager as the field Expr1.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39600259
ps.  Some 'flavours' of SQL have slightly different syntax so the above might not work as quoted, it might need slight modification.  The principle however is the same.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

14 Experts available now in Live!

Get 1:1 Help Now