Click here to Skip to main content
15,992,684 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
string todate = txtToDate1.Text;
                string fromtime = DropDownList2.SelectedItem.Text;
                string totime = DropDownList3.SelectedItem.Text;

                string fromdatetime = fromdate + "_" + fromtime;
                string todatetime = todate + "_" + totime;

            
                con.ConnectionString = constr;

                //create instance for command object 
                OleDbCommand cmd = new OleDbCommand();
               

                cmd.Connection = con;   
                // set your file name in the below query
                cmd.CommandText = "select * from " + fromdatetime + ".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());




string fromdatetime is something like 12162013_0730.csv and string todatetime is something like 12162013_0930.csv...how can i use for loop to read the file in between the fromdatetime todatetime... read 12162013_0730.csv ,12162013_0830.csv,12162013_0930.csv, one file at a time.
Posted
Updated 29-Dec-13 19:05pm
v2

1 solution

Hi This might help you..



C#
string strfrom = "12162013_0730";
        string strto = "12162013_1030";

       var from =  DateTime.ParseExact(strfrom, "MMddyyyy_hhmm", CultureInfo.InvariantCulture);
       var to = DateTime.ParseExact(strto, "MMddyyyy_hhmm", CultureInfo.InvariantCulture);
       double interval  = 60;
       List<string> lstDateString = new List<string>();
       lstDateString.Add(strfrom);
       while (from.AddMinutes(interval) != to)
       {

           lstDateString.Add(from.AddMinutes(interval).ToString("MMddyyyy_hhmm"));
           interval = interval + 60;
       }
       lstDateString.Add(strto);

       foreach (string datestring in lstDateString)
       {
           string csv = datestring + ".csv";
           // your coding here..
       }
 
Share this answer
 
Comments
Karthik_Mahalingam 30-Dec-13 3:39am    
can you please explain more..
so that i can give u some suggestion..
acing wei 30-Dec-13 4:05am    
okay.. the 'for each' loop it works well in reading that 4 csv files in one time which is 0730.csv,0830.csv,0930csv,and 1030.csv..in the cmd.command i count the pass value .however the gridview will only show the last csv "pass value" table which is 1030.csv...can it show four different table of "pass value" instead of the last one only..can i store the value each time it loops.....
Karthik_Mahalingam 30-Dec-13 4:12am    
ofcourse it will show only the last value. since you are looping it..

in grid u need to show all 4 datatable combined ??
acing wei 30-Dec-13 4:19am    
can it be looping first time then store the value, looping second time store the value and in the end got 4 value ... yes...my grid/mychart need to show like: at0730 how many pass, 0830 how many pass...something like that ... can it be done?
Karthik_Mahalingam 30-Dec-13 4:22am    
you can do one thing.
in the loop. u store all the tables in a dataset..
and use the dataset for binding in grid. as per your need..

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