Solved

C#, SQL database Evaluate data

Posted on 2013-10-25
2
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

628 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