Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
OleDbCommand cmd = new OleDbCommand();

                        cmd.Connection = con;
                        // set your file name in the below query
                        cmd.CommandText = "SELECT * FROM " + csv ;
     
                        //Open Oledb Connection to read CSV file 
                        con.Open();

                        //Create one datatable to store data from CSV file
                        DataTable dt = new DataTable();

                        // Load Data into the datatable 
                        dt.Load(cmd.ExecuteReader());
                        con.Close();

                        foreach (DataRow row in dt.Rows)
                        {
                            lstData.Add(new Tablelist() { process = row["process"] + "", Event = row["Event"] + "", status = row["status"] + "" });
                            
                        }

                        // assign the lstData to the gridview..
                        GridViewShow.DataSource = lstData;
                        GridViewShow.DataBind();

This code allowed me to read 3 csv files which is 0730.csv, 0830.csv,0930.csv and show all in gridview with this 3 columns : process, event, status...
can I actually show it with this output format
0730|0830|0930|
pass|pass|pass|

1)i need to show this table ,
2)pass is the total count of how many pass,
3)which is read from the "status column" of this 3 csv :0730.csv, 0830.csv,0930.csv
Posted
Updated 1-Jan-14 18:04pm
v2
Comments
ZurdoDev 1-Jan-14 21:38pm    
I don't understand your question or where you are stuck.
acing wei 1-Jan-14 22:03pm    
my code above which is read from 3 csv files :0730.csv, 0830.csv,0930.csv..merge in one table giving me this table

process|event|status|
abcdef|1234556|pass/fail|


what i want the output ,read from the "status column" above ,count the total pass and fail, give this table according to csv that read.
0730|0830|0930|
pass|pass|pass|

pass = how many pass..
Karthik_Mahalingam 2-Jan-14 1:27am    
acing, will continue here..
you need only the pass count ?
acing wei 2-Jan-14 1:42am    
and also the fail count...

Hi try like this...
C#
foreach (DataRow row in dt.Rows)
        {
            lstData.Add(new Tablelist() { FileName=csv,  process = row["process"] + "", Event = row["Event"] + "", status = row["status"] + "" });

        }
    }
        DataTable dtoutput = new DataTable();
       var columnNames =  lstData.Select(k => k.FileName).Distinct();
       foreach (string columnName in columnNames)       
           dtoutput.Columns.Add(columnName, typeof(string));
       DataRow newrowPassCount = dtoutput.NewRow();
         foreach (string columnName in columnNames) {
            int count = lstData.Where(k=> k.FileName == columnName).Count(k => k.status == "Pass");
            newrowPassCount[columnName] = count; 
        }
         dtoutput.Rows.Add(newrowPassCount);

         DataRow newrowFailCount = dtoutput.NewRow();
         foreach (string columnName in columnNames)
         {
             int count = lstData.Where(k => k.FileName == columnName).Count(k => k.status == "Fail");
             newrowFailCount[columnName] = count;
         }
         dtoutput.Rows.Add(newrowFailCount);

         gridview.datasource = dtoutput;
         gridview.databind();


add a new property FileName in the class

C#
class Tablelist
{
    public string process { get; set; }
    public string Event { get; set; }
    public string status { get; set; }
    public string FileName { get; set; }
}
 
Share this answer
 
Comments
acing wei 2-Jan-14 3:51am    
it display 0 in the column..
Karthik_Mahalingam 2-Jan-14 3:56am    
which column?
Karthik_Mahalingam 2-Jan-14 3:57am    
FileName=csv.Replace(".csv","").Replace(".CSV","");
acing wei 2-Jan-14 3:58am    
all column...i debug and see the value from list data didn't go into the int count
Karthik_Mahalingam 2-Jan-14 4:07am    
check the case for "pass"
Loop for one DataTable and count that column store in a Variable.
Then go for next, count the same column and store in another variable and so on for other DataTables.

Then sum all the variable counts. You now have the total count.

Create a DataTable and make columns as you need and show these data under appropriate columns.
 
Share this answer
 
Comments
acing wei 1-Jan-14 23:31pm    
yes, when everytime looping i need to store it, how to store a variable.. how to use count and sum in a datatable?
Show me what you have tried, if there are any problems, then I will try to rectify it.
I can't understand. Can you please explain what are trying to achieve? I am getting confused.
acing wei 14-Jan-14 20:13pm    
i want to achieve a new row of newrowpasscount everytime it loops..because a newrowpasscount will giving me different value everytime it loops..i need new row to put my newrowpasscount ..

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