Solved

C#, SQL database Evaluate data

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 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