In my code behind I have put an query result in dataset which returns a table like as bellow:
Sl_NO COMPLEATED_ON SCORE IS_PRESENT MAX_VALUE
1 29/07/2010 4 0 12
2 29/07/2010 5 0 13
3 29/07/2010 6 1 23
4 29/07/2010 7 1 44
5 6 1
6 5 0
7 4 1
My reqirement is that I need to count total number non empty rows which column name is COMPLEATED_ON.I mean from above example it should return 4 since rest three rows of the column COMPLEATED_ON is empty.Can any one tell me how to do this in C#?
Count the number of rows and columns of Dataframe using len() function. The len() function returns the length rows of the Dataframe, we can filter a number of columns using the df. columns to get the count of columns.
ROWS is useful if we wish to find out the number of rows in a range. The most basic formula used is =ROWS(rng). The function counted the number of rows and returned a numerical value as the result. When we gave the cell reference B6, it returned the result of 1 as only one reference was given.
Try this:
dsDataSet.Tables[0].Select("COMPLEATED_ON is not null").Length;
You can use the Select
method of the DataTable:
DataTable table = DataSet.Tables[tableName];
string expression = "COMPLEATED_ON IS NOT NULL AND COMPLEATED_ON <> ''";
DataRow[] foundRows = table.Select(expression);
int rowCount = foundRows.Length;
Or here's a brute force way:
int count = 0;
DataTable table = DataSet.Tables[tableName];
foreach (DataRow row in table.Rows)
{
string completed = (string)row["COMPLEATED_ON"];
if (!string.IsNullOrEmpty(completed))
{
count++;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With