By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,962 Members | 2,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,962 IT Pros & Developers. It's quick & easy.

Displaying number of rows as a text (no datagrid)

P: 2
Hello. I am trying to find information on how to display calculations on the screen using .Net. I am not using a data grid. What I'm trying to do is display how many rows in a database and then do something with that. So for example, in my SQL database I have 345 rows each with an employees info. On the last column is status. 1 = still working and 2 = not working here any more.

I would like to display.

Number of employees = 345
Number of employees who left = 125
Jun 12 '07 #1
Share this Question
Share on Google+
4 Replies


dip_developer
Expert 100+
P: 648
Hello. I am trying to find information on how to display calculations on the screen using .Net. I am not using a data grid. What I'm trying to do is display how many rows in a database and then do something with that. So for example, in my SQL database I have 345 rows each with an employees info. On the last column is status. 1 = still working and 2 = not working here any more.

I would like to display.

Number of employees = 345
Number of employees who left = 125
A simple SQL query
Select COUNT(*) FROM tblEmployee WHERE status='2' will give you the no of employees who left.
Jun 12 '07 #2

P: 11
Hello. I am trying to find information on how to display calculations on the screen using .Net. I am not using a data grid. What I'm trying to do is display how many rows in a database and then do something with that. So for example, in my SQL database I have 345 rows each with an employees info. On the last column is status. 1 = still working and 2 = not working here any more.

I would like to display.

Number of employees = 345
Number of employees who left = 125
Hi

lets take an eg. where dataset name is ds and datatable name is employees.

add following lines to your code.

//to find no. of employees

DataView dv = new DataView(ds.employees);
dv.RowFilter = "status = 1";
int iExist = ds.employees.rows.count;

//to find no. of left employees
dv.RowFilter = "status = 2";
int iLeft = ds.employees.rows.count;

Regards,

Guru
Jun 12 '07 #3

nateraaaa
Expert 100+
P: 663
A simple SQL query
Select COUNT(*) FROM tblEmployee WHERE status='2' will give you the no of employees who left.
All you need to do is run the query (stored procedure is preferred) above and then assign the result to a label control.

Nathan
Jun 12 '07 #4

P: 2
Great! I tried the SQL query and it works fine. Thank you for your help.

One last question. Is there a way to do the following?

SELECT COUNT(Status) AS Total FROM tblEmployee WHERE Status='2' AND Status = '4'

Also, someone mentioned adding this to store procedure. How can I add both query in there? so for example.

Alter Procedure dbo.Status
@Status int
As
SELECT COUNT(*) FROM tblEmployee WHERE Status='2'
AND
SELECT COUNT(Status) AS Total FROM tblEmployee WHERE Status='2' AND Status = '4'
and also add the other count above.
Jun 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.