Click here to Skip to main content
15,883,731 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi frnds i have an task like The table has an value as
0 1 1 1 0 0
This actually the 1 row in this i need to find how mny 0's and 1's where present in it 


pls do help me Thank You...,,
Posted
Comments
Dholakiya Ankit 3-Aug-13 2:20am    
in a one row or columns?
Member 10185097 3-Aug-13 2:25am    
In one row i should get the output as number of 0's as 3 and 1 as 3
Dholakiya Ankit 3-Aug-13 2:43am    
take a look at solution
Thanks7872 3-Aug-13 2:35am    
What do you mean by 'row'? Where you have this row? You mean to have this in string?
Member 10185097 3-Aug-13 2:38am    
Ya i got in a string after that i dnt no hw to proceed to get count values...

C#
int noofzerors=0;
                int noofones = 0;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (dt.Rows[0][i].ToString() == "0")
                    {
                        noofzerors++;
                    }
                    if (dt.Rows[0][i].ToString() == "1")
                    {
                        noofones++;
                    }

                }
                here you will get your result....regards :)
 
Share this answer
 
Comments
Dholakiya Ankit 3-Aug-13 2:56am    
this is one row only
Member 10185097 3-Aug-13 3:02am    
ya oly one row value
Dholakiya Ankit 3-Aug-13 3:08am    
yes then check solution
Member 10185097 3-Aug-13 3:11am    
It works Thanks lot...
Dholakiya Ankit 3-Aug-13 3:16am    
welcome
Check the below link

count.php[^]

use count with distinct.

Hope it will help..
 
Share this answer
 
Comments
Thanks7872 3-Aug-13 2:32am    
He didnt specified that he want to count rows in sql table. And he is aimed to check in row.
Dholakiya Ankit 3-Aug-13 3:21am    
yes he needs in datatable

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900