Solved

C#, SQL database Evaluate data

Posted on 2013-10-25
2
313 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Both Easy and Powerful 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.wikipedia.org/wiki/PHP  Very powerful.  But a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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