Solved

C#, SQL database Evaluate data

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Have issues with Query MySQL 9 54
Linq Help 1 34
Problem with Simple PHP/mySQL Query 3 50
Connection String 16 41
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

937 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

7 Experts available now in Live!

Get 1:1 Help Now